{"id":63820,"date":"2025-04-29T13:57:36","date_gmt":"2025-04-29T05:57:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63820\/"},"modified":"2025-04-29T13:57:36","modified_gmt":"2025-04-29T05:57:36","slug":"docker%e8%bf%90%e8%a1%8c%e5%ae%b9%e5%99%a8%e6%80%8e%e4%b9%88%e7%94%a8-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63820\/","title":{"rendered":"docker\u8fd0\u884c\u5bb9\u5668\u600e\u4e48\u7528"},"content":{"rendered":"<blockquote><p>\n  \u8981\u8fd0\u884c docker \u5bb9\u5668\uff0c\u9700\u4f9d\u6b21\u6267\u884c\uff1a\u62c9\u53d6\u955c\u50cf (docker pull )\u521b\u5efa\u5bb9\u5668 (docker run -it &#8211;rm &#8211;name )\u4ea4\u4e92\u64cd\u4f5c\u5bb9\u5668 (docker exec -it \/bin\/bash)\u7aef\u53e3\u6620\u5c04 (docker run -it &#8211;rm &#8211;name my-nginx -p 8080:80 nginx)\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf (docker run -it &#8211;rm &#8211;name\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/05\/2024060509482287723.jpg\" class=\"aligncenter\" title=\"docker\u8fd0\u884c\u5bb9\u5668\u600e\u4e48\u7528\u63d2\u56fe\" alt=\"docker\u8fd0\u884c\u5bb9\u5668\u600e\u4e48\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8fd0\u884c Docker \u5bb9\u5668<\/strong><\/p>\n<p>\u8fd0\u884c Docker \u5bb9\u5668\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u62c9\u53d6\u955c\u50cf<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u9700\u8981\u62c9\u53d6\u6240\u9700\u955c\u50cf\u3002\u955c\u50cf\u662f\u5305\u542b\u5e94\u7528\u7a0b\u5e8f\u3001\u5e93\u548c\u4f9d\u8d56\u9879\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u62c9\u53d6\u955c\u50cf\uff1a<\/p>\n<pre>docker pull &lt;\u955c\u50cf\u540d\u79f0&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u62c9\u53d6 Nginx \u955c\u50cf\uff1a<\/p>\n<pre>docker pull nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u521b\u5efa\u5bb9\u5668<\/strong><\/p>\n<p>\u62c9\u53d6\u955c\u50cf\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528  run \u547d\u4ee4\u521b\u5efa\u5bb9\u5668\u3002\u8be5\u547d\u4ee4\u5141\u8bb8\u6307\u5b9a\u5bb9\u5668\u7684\u8fd0\u884c\u914d\u7f6e\uff0c\u4f8b\u5982\u7aef\u53e3\u6620\u5c04\u548c\u73af\u5883\u53d8\u91cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u793a\u4f8b\uff1a<\/p>\n<pre>docker run -it --rm --name &lt;\u5bb9\u5668\u540d\u79f0&gt; &lt;\u955c\u50cf\u540d\u79f0&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;my-&#8221; \u7684\u5bb9\u5668\uff1a<\/p>\n<pre>docker run -it --rm --name my-nginx nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4ea4\u4e92\u64cd\u4f5c<\/strong><\/p>\n<p>\u5bb9\u5668\u521b\u5efa\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ea4\u4e92\u5f0f\u6a21\u5f0f\u8fdb\u5165\u5bb9\u5668\u3002\u8fd9\u5141\u8bb8\u5728\u5bb9\u5668\u5185\u6267\u884c\u547d\u4ee4\u548c\u67e5\u770b\u8f93\u51fa\u3002\u4ee5\u4e0b\u662f\u8fdb\u5165\u5bb9\u5668\u7684\u547d\u4ee4\uff1a<\/p>\n<pre>docker exec -it &lt;\u5bb9\u5668\u540d\u79f0&gt; \/bin\/bash<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u7aef\u53e3\u6620\u5c04<\/strong><\/p>\n<p>\u5982\u679c\u5bb9\u5668\u9700\u8981\u66b4\u9732\u7aef\u53e3\u4ee5\u4e0e\u5916\u90e8\u4e16\u754c\u901a\u4fe1\uff0c\u5219\u9700\u8981\u8fdb\u884c\u7aef\u53e3\u6620\u5c04\u3002\u8fd9\u53ef\u4ee5\u4f7f\u7528 -p \u6807\u5fd7\u5b8c\u6210\uff0c\u8be5\u6807\u5fd7\u6307\u5b9a\u4e3b\u673a\u7aef\u53e3\u548c\u5bb9\u5668\u7aef\u53e3\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c06\u5bb9\u5668\u4e2d\u7684 80 \u7aef\u53e3\u6620\u5c04\u5230\u4e3b\u673a\u4e0a\u7684 8080 \u7aef\u53e3\uff1a<\/p>\n<pre>docker run -it --rm --name my-nginx -p 8080:80 nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u73af\u5883\u53d8\u91cf<\/strong><\/p>\n<p>\u53ef\u4ee5\u5728\u521b\u5efa\u5bb9\u5668\u65f6\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u4ee5\u4fbf\u5bb9\u5668\u5185\u7684\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u8bbf\u95ee\u5b83\u4eec\u3002\u4f7f\u7528 -e \u6807\u5fd7\u6307\u5b9a\u73af\u5883\u53d8\u91cf\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>docker run -it --rm --name my-nginx -e MY_ENV_VAR=value nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u505c\u6b62\u548c\u5220\u9664\u5bb9\u5668<\/strong><\/p>\n<p>\u5f53\u5bb9\u5668\u4e0d\u518d\u9700\u8981\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 docker stop \u547d\u4ee4\u505c\u6b62\u5b83\uff0c\u7136\u540e\u4f7f\u7528 docker rm \u547d\u4ee4\u5220\u9664\u5b83\u3002\u4ee5\u4e0b\u793a\u4f8b\u663e\u793a\u5982\u4f55\u505c\u6b62\u548c\u5220\u9664 &#8220;my-nginx&#8221; \u5bb9\u5668\uff1a<\/p>\n<pre>docker stop my-nginx\ndocker rm my-nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8fd0\u884c\u5bb9\u5668\u600e\u4e48\u7528\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u8fd0\u884c docker \u5bb9\u5668\uff0c\u9700\u4f9d\u6b21\u6267\u884c\uff1a\u62c9\u53d6\u955c\u50cf (docker pull )\u521b\u5efa\u5bb9\u5668 (docker run -it &#8211;rm &#8211;name )\u4ea4\u4e92\u64cd\u4f5c\u5bb9\u5668 (docker exec -it \/bin\/bash)\u7aef\u53e3\u6620\u5c04 (docker run -it &#8211;rm &#8211;name my-nginx -p 8080:80 nginx)\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf (docker run -it &#8211;rm &#8211;name \u5982\u4f55\u8fd0\u884c Docker \u5bb9\u5668 \u8fd0\u884c Docker \u5bb9\u5668\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u62c9\u53d6\u955c\u50cf \u9996\u5148\uff0c\u9700\u8981\u62c9\u53d6\u6240\u9700\u955c\u50cf\u3002\u955c\u50cf\u662f\u5305\u542b\u5e94\u7528\u7a0b\u5e8f\u3001\u5e93\u548c\u4f9d\u8d56\u9879\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u62c9\u53d6\u955c\u50cf\uff1a docker pull &lt;\u955c\u50cf\u540d\u79f0&gt; \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff0c\u8981\u62c9\u53d6 Nginx \u955c\u50cf\uff1a docker pull nginx \u767b\u5f55\u540e\u590d\u5236 2. \u521b\u5efa\u5bb9\u5668 \u62c9\u53d6\u955c\u50cf\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528 run \u547d\u4ee4\u521b\u5efa\u5bb9\u5668\u3002\u8be5\u547d\u4ee4\u5141\u8bb8\u6307\u5b9a\u5bb9\u5668\u7684\u8fd0\u884c\u914d\u7f6e\uff0c\u4f8b\u5982\u7aef\u53e3\u6620\u5c04\u548c\u73af\u5883\u53d8\u91cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u793a\u4f8b\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-63820","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=63820"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63820\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}