{"id":261,"date":"2023-04-16T14:48:08","date_gmt":"2023-04-16T06:48:08","guid":{"rendered":"https:\/\/www.bunnyism.com\/?p=261"},"modified":"2024-12-18T21:46:51","modified_gmt":"2024-12-18T13:46:51","slug":"docker-%e5%ad%98%e5%82%a8%e5%8d%b7%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.bunnyism.com\/?p=261","title":{"rendered":"docker \u5b58\u50a8\u5377\u7ba1\u7406"},"content":{"rendered":"<div class=\"lake-content\">\n<p id=\"ue978d392\" class=\"ne-p\"><span class=\"ne-text\">\u6240\u8c13\u7684\u5bb9\u5668\u6570\u636e\u6301\u4e45\u5316\uff0c\u5c31\u662f\u5c06\u5bbf\u4e3b\u673a\u7684\u67d0\u4e2a\u76ee\u5f55\uff0c\u6302\u8f7d\u5230\u5bb9\u5668\u7684\u6307\u5b9a\u8def\u5f84\u6302\u8f7d\u70b9\uff0c\u5f53\u5220\u9664\u5bb9\u5668\u65f6\uff0c\u5bbf\u4e3b\u673a\u7684\u6570\u636e\u5e76\u4e0d\u4f1a\u4e22\u5931<\/span><\/p>\n<p id=\"u6c8c0c81\" class=\"ne-p\"><span class=\"ne-text\">\u5f53\u5bb9\u5668\u7684\u6302\u8f7d\u70b9\u6709\u6570\u636e\u65f6\uff0c\u76f4\u63a5\u4f7f\u7528\u5bbf\u4e3b\u673a\u7684\u8def\u5f84\u6302\u8f7d\uff0c\u53ef\u80fd\u4f1a\u5c06\u5bb9\u5668\u539f\u6709\u7684\u6570\u636e\u76f4\u63a5\u6e05\u7a7a\u5e76\u8986\u76d6<\/span><\/p>\n<p>\u6211\u4eec\u8bdd\u4e0d\u591a\u8bf4 \u76f4\u63a5\u4e0a\u6848\u4f8b~<\/p>\n<div class=\"lake-content\">\n<h3 id=\"tCu4I\"><span class=\"ne-text\">\u5728\u5bbf\u4e3b\u673a\u521b\u5efa\u76ee\u5f55<\/span><\/h3>\n<blockquote><p>mkdir -pv \/volume\/data\/<\/p>\n<p>mkdir -pv \/volume\/data2\/<\/p>\n<p>echo test &gt; \/volume\/data\/index.html<\/p>\n<p>docker run -d &#8211;name t4 &#8211;network host -v \/volume\/data\/:\/usr\/share\/nginx\/html\/ nginx<\/p>\n<p>#\u67e5\u770b\u5bb9\u5668\u7684\u7f51\u7edcIP\uff08\u4f7f\u7528\u6865\u63a5\u7f51\u7edc\u6216\u8005\u81ea\u5b9a\u4e49\u7f51\u7edc\u65f6\u4f7f\u7528 \u4e0a\u9762\u4f7f\u7528\u7684host \u53ef\u4ee5\u76f4\u63a5\u5bbf\u4e3b\u673a\u7f51\u7edcip\u8fdb\u884c\u8bbf\u95ee\u5373\u53ef\uff09<\/p>\n<p>docker inspect t4 | grep IPAddress<\/p>\n<p>#curl ip \u770b\u5230\u6211\u4eec\u5199\u5165\u7684\u5185\u5bb9<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h3 id=\"oUoW7\"><span class=\"ne-text\">\u5220\u9664\u5bb9\u5668\u89c2\u5bdf\u6570\u636e\u662f\u5426\u4e22\u5931<\/span><\/h3>\n<blockquote><p>#\u5220\u9664\u5bb9\u5668<\/p>\n<p>docker container rm -f `docker container ps -qa`<\/p>\n<p>#\u518d\u6b21\u521b\u5efa\u5bb9\u5668\u5e76\u4e14\u6302\u8f7d<\/p>\n<p>docker run -d &#8211;name c1 &#8211;network host -v \/volume\/data\/:\/usr\/share\/nginx\/html\/ nginx<\/p>\n<p>#\u5185\u5bb9\u5f53\u7136\u4e0d\u4f1a\u4e22\u5931<\/p><\/blockquote>\n<h3>\u591a\u4e2a\u5bb9\u5668\u6302\u8f7d\u4e00\u4e2a\u76ee\u5f55<\/h3>\n<p>-p \u53c2\u6570\u662f\u5411\u5bbf\u4e3b\u673a\u66b4\u9732\u5bb9\u5668\u5185\u90e8\u768480\u7aef\u53e3<\/p>\n<p>&#8211;volumes-from \u548ct5\u5171\u4eab\u6302\u8f7d\u76ee\u5f55<\/p>\n<blockquote><p>docker run -d &#8211;name t5 -p 81:80 -v \/volume\/data\/:\/usr\/share\/nginx\/html\/ nginx<\/p>\n<p>docker run -d &#8211;name t6 -p 82:80 &#8211;volumes-from nginx<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h3 id=\"goGOt\"><span class=\"ne-text\">\u4e00\u4e2a\u5bb9\u5668\u53ef\u4ee5\u914d\u7f6e\u591a\u4e2a\u5bbf\u4e3b\u673a\u76ee\u5f55<\/span><\/h3>\n<blockquote><p>docker run -d &#8211;name y1 -v \/volume\/data\/:\/volume\/data\/ -v \/volume\/data2\/:\/volume\/data2\/ alpine<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h3 id=\"rrBTd\"><span class=\"ne-text\">docker\u5185\u7f6e\u7684\u5b58\u50a8\u5377\u7ba1\u7406<\/span><\/h3>\n<div class=\"lake-content\">\n<h4 id=\"dGmTl\"><span class=\"ne-text\">\u521b\u5efa\u5b58\u50a8\u5377<\/span><\/h4>\n<blockquote><p>docker volume create v1<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h4 id=\"Tzgmc\"><span class=\"ne-text\">\u67e5\u770b\u5b58\u50a8\u5377\u5217\u8868<\/span><\/h4>\n<blockquote><p>docker volume ls<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h4 id=\"vieqq\"><span class=\"ne-text\">\u9ed8\u8ba4\u5b58\u50a8\u5377\u4f4d\u7f6e\u8def\u5f84<\/span><\/h4>\n<blockquote><p>\/var\/lib\/docker\/volumes\/<\/p><\/blockquote>\n<\/div>\n<div class=\"lake-content\">\n<h4 id=\"FM1JM\"><span class=\"ne-text\">\u67e5\u770b\u5b58\u50a8\u5377\u7684\u8be6\u7ec6\u4fe1\u606f<\/span><\/h4>\n<blockquote><p>docker volume inspect v1<\/p>\n<p>{<br \/>\n&#8220;CreatedAt&#8221;: &#8220;2022-03-05T10:12:27+08:00&#8221;,<br \/>\n&#8220;Driver&#8221;: &#8220;local&#8221;,<br \/>\n&#8220;Labels&#8221;: {},<br \/>\n&#8220;Mountpoint&#8221;: &#8220;\/var\/lib\/docker\/volumes\/v1\/_data&#8221;,<br \/>\n&#8220;Name&#8221;: &#8220;v1&#8221;,<br \/>\n&#8220;Options&#8221;: {},<br \/>\n&#8220;Scope&#8221;: &#8220;local&#8221;<br \/>\n}<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h3 id=\"GR9Sx\"><span class=\"ne-text\">\u5bb9\u5668\u4f7f\u7528\u5b58\u50a8\u5377<\/span><\/h3>\n<div class=\"lake-content\">\n<h4 id=\"ziKhW\"><span class=\"ne-text\">\u5bb9\u5668\u4f7f\u7528\u5df2\u6709\u7684\u5b58\u50a8\u5377<\/span><\/h4>\n<div class=\"lake-content\">\n<p id=\"ub8424899\" class=\"ne-p\"><span class=\"ne-text\">\u5bb9\u5668\u521b\u5efa\u65f6\u82e5\u5b58\u50a8\u5377\u4e0d\u5b58\u5728\uff0c\u5219\u4f1a\u76f4\u63a5\u521b\u5efa \u7136\u540e\u5c06\u5bb9\u5668\u5185\u90e8\u6620\u5c04\u7684\u76ee\u5f55\u5185\u5bb9\u62f7\u8d1d\u5230\u5916\u90e8\u865a\u62df\u673a\u6240\u5728\u7684\u5b58\u50a8\u5377\u4f4d\u7f6e<\/span><\/p>\n<\/div>\n<blockquote><p>docker run -d &#8211;name t7 -p 88:80 -v v1:\/usr\/share\/nginx\/html nginx<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h4 id=\"xQNQt\"><span class=\"ne-text\">\u533f\u540d(\u968f\u673a)\u5b58\u50a8\u5377<\/span><\/h4>\n<div class=\"lake-content\">\n<p id=\"u87c9fc40\" class=\"ne-p\"><span class=\"ne-text\">\u521b\u5efa\u5bb9\u5668\u65f6\u82e5\u4e0d\u6307\u5b9a\u5b58\u50a8\u5377\uff0c\u5219\u9ed8\u8ba4\u4f1a\u751f\u6210\u533f\u540d(\u968f\u673a)\u5b58\u50a8\u5377<\/span><\/p>\n<\/div>\n<blockquote><p>docker run -d &#8211;name t8 -p 89:80 -v \/usr\/share\/nginx\/html nginx<\/p><\/blockquote>\n<p>\u4f7f\u7528<span class=\"ne-text\">\u533f\u540d(\u968f\u673a)\u5b58\u50a8\u6216\u8005\u5fd8\u8bb0\u4e86 \u4e0d\u77e5\u9053\u8def\u5f84\u5728\u54ea\u91cc\u600e\u4e48\u529e<br \/>\n<\/span><\/p>\n<blockquote><p>docker container inspect -f &#8220;{{.Mounts}}&#8221; t8<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h3 id=\"LU4xf\"><span class=\"ne-text\">\u79fb\u9664\u6240\u6709\u672a\u4f7f\u7528\u7684\u5b58\u50a8\u5377<\/span><\/h3>\n<p>\u5f53\u7a7a\u95f4\u4e0d\u8db3\u65f6\u53ef\u4ee5\u4f7f\u7528 \u4f46\u662f\u5fc5\u987b\u641e\u660e\u767d\u5b58\u50a8\u5377\u4fdd\u5b58\u7684\u6570\u636e\u662f\u5426\u6709\u7528~<\/p>\n<div class=\"lake-content\">\n<p id=\"u98652766\" class=\"ne-p\"><span class=\"ne-text\">\u5220\u9664\u4f7f\u7528\u7684\u5b58\u50a8\u5377\u65f6\u5c06\u65e0\u6cd5\u5220\u9664 \u51fa\u4e8e\u4fdd\u62a4\u7684\u4f5c\u7528<\/span><\/p>\n<\/div>\n<blockquote><p>docker volume prune -f<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h3 id=\"a4jSF\"><span class=\"ne-text\">\u5220\u9664\u6307\u5b9a\u7684\u5b58\u50a8\u5377<\/span><\/h3>\n<blockquote><p>docker volume rm \u5b58\u50a8\u5377\u540d<\/p><\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"padding-left: 40px;\"><strong>\u4e0b\u4e00\u8282\u5c06\u8bf4\u660eDockerfile~<\/strong><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6240\u8c13\u7684\u5bb9\u5668\u6570\u636e\u6301\u4e45\u5316\uff0c\u5c31\u662f\u5c06\u5bbf\u4e3b\u673a\u7684\u67d0\u4e2a\u76ee\u5f55\uff0c\u6302\u8f7d\u5230\u5bb9\u5668\u7684\u6307\u5b9a\u8def\u5f84\u6302\u8f7d\u70b9\uff0c\u5f53\u5220\u9664\u5bb9\u5668\u65f6\uff0c\u5bbf\u4e3b\u673a\u7684\u6570\u636e\u5e76\u4e0d\u4f1a\u4e22\u5931 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":193,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts\/261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=261"}],"version-history":[{"count":44,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts\/261\/revisions"}],"predecessor-version":[{"id":305,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts\/261\/revisions\/305"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/media\/193"}],"wp:attachment":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}