{"id":631,"date":"2025-04-11T20:36:32","date_gmt":"2025-04-11T12:36:32","guid":{"rendered":"https:\/\/awamyy.top\/?p=631"},"modified":"2025-04-23T14:34:45","modified_gmt":"2025-04-23T06:34:45","slug":"docker%e5%b8%b8%e8%a7%81%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/awamyy.top\/?p=631","title":{"rendered":"Docker\u57fa\u672c\u64cd\u4f5c"},"content":{"rendered":"\n<p style=\"font-size:28px\"><strong>1.\u5b89\u88c5docker\u53ef\u53c2\u7167\u5b98\u65b9\u6587\u6863<\/strong><\/p>\n\n\n\n<p><strong>\u8be6\u7ec6\u53c2\u8003\uff1a<\/strong><a href=\"https:\/\/docs.docker.com\/engine\/install\/\">Install | Docker Docs<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>docker\u7684\u955c\u50cf\u6e90\uff1a<\/strong>http:\/\/mirrors.aliyun.com\/docker-ce\/linux\/centos\/docker-ce.repo\n<strong>\u6307\u5b9a\u4e0b\u8f7ddocker\u7684\u6e90\u4f8b\u5982(CentOS 8.0)\uff1a<\/strong>\nsudo yum install -y yum-utils\nsudo yum-config-manager \\\n--add-repo \\\nhttp:&#47;&#47;mirrors.aliyun.com\/docker-ce\/linux\/centos\/docker-ce.repo\n<strong>\u6307\u5b9a\u4e0b\u8f7d\u955c\u50cf\u6e90\u4f8b\u5982\uff1a<\/strong>\nsudo mkdir -p \/etc\/docker\nsudo tee \/etc\/docker\/daemon.json &lt;&lt;-'EOF'\n{\n\"registry-mirrors\":&#91;\"https:\/\/docker.1ms.run\",\n \"https:\/\/docker.1panel.live\/\",\n \"https:\/\/hub-mirror.c.163.com\",\n \"https:\/\/mirror.aliyuncs.com\"]\n}\nEOF\nsudo systemctl daemon-reload\nsudo systemctl restart docker<\/code><\/pre>\n\n\n\n<p style=\"font-size:28px\"><strong>2.\u5e38\u7528\u547d\u4ee4<\/strong><\/p>\n\n\n\n<p><strong>\u8be6\u7ec6\u53c2\u8003<\/strong>\uff1a<a href=\"https:\/\/docs.docker.com\/reference\/cli\/docker\/\">docker | Docker Docs<\/a><\/p>\n\n\n\n<p style=\"font-size:20px\"><strong>2.1 \u4e0b\u8f7d\u955c\u50cf<\/strong> docker pull &lt;\u955c\u50cf\u540d:\u7248\u672c&gt; <\/p>\n\n\n\n<pre class=\"wp-block-code has-normal-font-size\"><code>\u82e5\u4e0d\u6307\u5b9a\u7248\u672c\u5219\u4e0b\u8f7d\u6700\u65b0\u7248\uff0c\u4f8b\u5982docker pull nginx\uff0c\u5219\u4f1a\u4e0b\u8f7d\u6700\u65b0\u7248\u7684nginx\u955c\u50cf<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>2.2 \u67e5\u770b\u955c\u50cf\u5217\u8868\u53ca\u76f8\u5173\u4fe1\u606f<\/strong> docker images<\/p>\n\n\n\n<p style=\"font-size:20px\"><strong>2.3 \u5220\u9664\u955c\u50cf<\/strong> docker rmi &lt;\u955c\u50cf\u540d:\u7248\u672c\/image id&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>\u82e5\u4e0d\u6307\u5b9a\u7248\u672c\u5219\u4e0b\u8f7d\u6700\u65b0\u7248\uff0c\u4f8b\u5982docker pull nginx\uff0c\u5219\u4f1a\u4e0b\u8f7d\u6700\u65b0\u7248\u7684nginx\u955c\u50cf<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>2.4 \u542f\u52a8\u65b0\u5bb9\u5668<\/strong> docker run [options] &lt;\u955c\u50cf\u540d:\u7248\u672c&gt; <\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>options\u53ca\u5176\u5b83\u53c2\u6570\u4f5c\u7528\uff1a\n<strong> &lt;\u955c\u50cf\u540d:\u7248\u672c&gt;<\/strong> \uff0c\u82e5\u4e0d\u6307\u5b9a\u955c\u50cf\u7248\u672c\u5219\u4f1a\u542f\u52a8\u6700\u65b0\u7248\uff0c\u82e5\u4e0d\u5b58\u5728\u955c\u50cf\u5219\u4f1a\u81ea\u52a8\u4e0b\u8f7d\n<strong> -d <\/strong>\uff0c\u4f7f\u955c\u50cf\u5728\u540e\u53f0\u8fd0\u884c\n<strong> --name &lt;\u522b\u540d&gt; <\/strong>\uff0c\u8d4b\u4e88\u5bb9\u5668\u522b\u540d\uff0c\u82e5\u4e0d\u8bbe\u7f6e\u5219\u968f\u673a\u751f\u6210\n<strong> -p &lt;\u5916\u90e8\u7aef\u53e3:\u5185\u90e8\u7aef\u53e3&gt; <\/strong>\uff0c\u7aef\u53e3\u6620\u5c04\uff0c\u9075\u5faa\u5916\u90e8\u7aef\u53e3:\u5185\u90e8\u7aef\u53e3\uff0c\u9700\u6ce8\u610f\u5916\u90e8\u7aef\u53e3\u662f\u5426\u91cd\u590d\uff0c\u800c\u6bcf\u4e00\u4e2a\u5bb9\u5668\u7684\u5185\u90e8\u7aef\u53e3\u662f\u72ec\u7acb\u7684\uff0c\u53ef\u4ee5\u91cd\u590d\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u6bcf\u542f\u52a8\u4e00\u4e2a\u5bb9\u5668\u5c31\u76f8\u5f53\u4e8e\u542f\u52a8\u4e86\u4e00\u53f0\u865a\u62df\u673a\uff0c\u6240\u4ee5\u53ef\u91cd\u590d\u3002\u53ef\u4f7f\u7528\u591a\u4e2a-p\u505a\u591a\u4e2a\u6620\u5c04\n<strong> -v &lt;\u5916\u90e8\u6587\u4ef6\u76ee\u5f55:\u5185\u90e8\u6587\u4ef6\u76ee\u5f55&gt;<\/strong>\uff0c\u76ee\u5f55\u6302\u8f7d\u548c\u5377\u6620\u5c04\uff0c\u5185\u90e8\u6587\u4ef6\u76ee\u5f55\u53ef\u67e5\u8be2\u76f8\u5e94\u6587\u6863\u3002\u76ee\u5f55\u6302\u8f7d\uff1a\u4ee5\u5916\u90e8\u6570\u636e\u4e3a\u51c6\uff0c\u82e5\u5916\u90e8\u65e0\u6570\u636e\u5219\u5185\u90e8\u4e5f\u65e0\u6570\u636e\u3002\u5377\u6620\u5c04\uff1a\u4ee5\u5185\u90e8\u6570\u636e\u4e3a\u51c6\uff0c\u82e5\u5916\u90e8\u65e0\u6570\u636e\u5219\u628a\u5185\u90e8\u6570\u636e\u642c\u51fa\u53bb\u3002\n<strong> --network &lt;\u7f51\u7edc\u540d\u79f0&gt;<\/strong>\uff0c\u6307\u5b9a\u5bb9\u5668\u52a0\u5165\u7684\u7f51\u7edc\n<strong> -e<\/strong>\uff0c\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff08\u4f8b5\uff09\n<strong>\u4f8b1\uff1a<\/strong>docker run -d --name myapp -p 80:80 mynginx:v1.0 -&gt;\u540e\u53f0\u8fd0\u884cmynginx:v1.0\u955c\u50cf\u66b4\u9732\u572880\u7aef\u53e3\u4e0a\uff0c\u5e76\u53d6\u522b\u540d\u4e3amyapp\n<strong>\u4f8b2\uff1a<\/strong>docker run -d -p 80:80 --name myapp -v \/app\/nghtml:\/usr\/share\/nginx\/html nginx -&gt;\u628a\u5916\u90e8\u7684\/app\/nghtml\u76ee\u5f55\u6302\u8f7d\u5230\/usr\/share\/nginx\/html\u76ee\u5f55\u4e0a\u3002\u6302\u8f7d\u540e\u76ee\u5f55\u5219\u4f1a\u53d8\u6210\u53cc\u5411\u94fe\u63a5(\u5185\u5916\u90e8\u4fee\u6539\uff0c\u6587\u4ef6\u90fd\u4f1a\u53d1\u751f\u53d8\u5316)\n<strong>\u4f8b3\uff1a<\/strong>docker run -d -p 88:80 -v \/app\/nghtml:\/usr\/share\/nginx\/html -v \/app\/ngconf:\/etc\/nginx --name myapp02 nginx -&gt;\u5728\u4f8b2\u57fa\u7840\u4e0a\u518d\u6302\u8f7dconf\u76ee\u5f55\u5230\u5916\u90e8(\u6302\u8f7d\u4f1a\u4ee5\u5916\u90e8\u6587\u4ef6\u4e3a\u51c6\uff0c\u82e5\u5916\u90e8\u6587\u4ef6\u4e3a\u7a7a\uff0c\u5219\u4f1a\u51fa\u73b0docker\u627e\u4e0d\u5230\u914d\u7f6e\u6587\u4ef6\u7684\u95ee\u9898\uff0c\u6240\u4ee5\u9700\u8981\u63d0\u524d\u914d\u7f6e\u597d\u5916\u90e8\u914d\u7f6e\u6587\u4ef6)\n<strong>\u4f8b4\uff1a<\/strong>docker run -d -p 98:80 -v \/app\/nghtml:\/usr\/share\/nginx\/html <mark style=\"background-color:rgba(0, 0, 0, 0);color:#c22828\" class=\"has-inline-color\">-v <\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#08b038\" class=\"has-inline-color\">ngconf<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#c22828\" class=\"has-inline-color\">:\/etc\/nginx<\/mark> --name myapp03 nginx -&gt;\u4f7f\u7528\u5377\u6620\u5c04\u89e3\u51b3\u4f8b3\u914d\u7f6e\u6587\u4ef6\u95ee\u9898\uff0c\u6620\u5c04\u540e\u4f4d\u7f6e\u4e3a\/var\/lib\/docker\/volumes\/&lt;volume-name&gt;(\u4f60\u7684\u5377\u540d\uff0c\u4e3a\u4ee5\u4e0a\u6807\u7eff\u5b57\u6bb5)\n<strong>\u4f8b5\uff1a<\/strong>docker run -d -p 6379:6379 -v \/app\/rd1:\/bitnami\/redis\/data -<mark style=\"background-color:rgba(0, 0, 0, 0);color:#c02727\" class=\"has-inline-color\">e REDIS_REPLICATION_MODE=master -e REDIS_PASSWORD=yourpassword<\/mark> --name redis1 bitnami\/redis<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>2.5 \u67e5\u770b\u6b63\u5728\u8fd0\u884c\u5f97\u5bb9\u5668 <\/strong>docker ps [options] <\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>options\u53ca\u5176\u5b83\u53c2\u6570\u4f5c\u7528\uff1a\n<strong> -a <\/strong>\uff0c\u67e5\u770b\u6240\u6709\u5bb9\u5668\u4fe1\u606f\uff0c\u5305\u542b\u672a\u8fd0\u884c\u7684\u5bb9\u5668\n <strong>-q<\/strong>\uff0c\u53ea\u6253\u5370\u5bb9\u5668ID\n<strong>\u4f8b\u5982\uff1a<\/strong>docker ps -aq \u4f1a\u6253\u5370\u6240\u6709\u5b58\u5728\u7684\u5bb9\u5668\u7684id<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>2.6 \u505c\u6b62\u8fd0\u884c\u5bb9\u5668<\/strong> docker stop &lt;\u5bb9\u5668ID\/ContainerID&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>\u53ef\u7528doker ps\u547d\u4ee4\u67e5\u770b\u5bb9\u5668id\uff0c\u5bb9\u5668id\u53ef\u7528\u524d\u4e09\u4f4d\uff0c\u7406\u8bba\u4e0a\u53ea\u8981\u80fd\u4e0e\u5176\u4ed6\u5bb9\u5668\u8fdb\u884c\u533a\u522b\u5373\u53ef<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>2.7 \u542f\u52a8\u505c\u6b62\u72b6\u6001\u7684\u5bb9\u5668<\/strong> docker start  &lt;\u955c\u50cf\u540d\/\u5bb9\u5668ID&gt;<\/p>\n\n\n\n<p style=\"font-size:20px\"><strong>2.8 \u91cd\u542f\u5bb9\u5668<\/strong> docker restart  &lt;\u5bb9\u5668ID&gt; <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u53ef\u91cd\u542f\u8fd0\u884c\u4e2d\u7684\u6216\u505c\u6b62\u7684\u5bb9\u5668<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>2.9 \u67e5\u770b\u5bb9\u5668\u72b6\u6001(\u5360\u7528)<\/strong> docker stats &lt;\u5bb9\u5668ID&gt;<\/p>\n\n\n\n<p style=\"font-size:20px\"><strong>2.10 \u67e5\u770b\u5bb9\u5668\u65e5\u5fd7<\/strong> docker logs &lt;\u5bb9\u5668ID&gt;<\/p>\n\n\n\n<p style=\"font-size:20px\"><strong>2.11 \u8fdb\u5165\u5bb9\u5668\u5185\u90e8bash\u63a7\u5236\u53f0<\/strong> docker exec [options] &lt;\u5bb9\u5668ID\/\u5bb9\u5668\u540d&gt; bash<\/p>\n\n\n\n<pre class=\"wp-block-code has-normal-font-size\"><code>options\u53ca\u5176\u5b83\u53c2\u6570\u4f5c\u7528\uff1a\n<strong> -it<\/strong>\uff0c\u4ee5\u4ea4\u4e92\u6a21\u5f0f\u8fdb\u5165\u5bb9\u5668\n\u5728exec\u6a21\u5f0f\u4e0b\uff0c\u8f93\u5165exit\u53ef\u9000\u51fa<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>2.12 \u5220\u9664\u5bb9\u5668<\/strong> docker rm [options] &lt;\u5bb9\u5668ID&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>options\u53ca\u5176\u5b83\u53c2\u6570\u4f5c\u7528\uff1a\n<strong> -f <\/strong>\uff0c\u5f3a\u5236\u5220\u9664\u8fd0\u884c\u4e2d\u7684\u5bb9\u5668\ntips:\n\u53ef\u4f7f\u7528docker rm -f $(docker ps -aq)\u5220\u9664\u6240\u6709\u5bb9\u5668<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>2.13 \u6253\u5305\u63d0\u4ea4\u5bb9\u5668(\u6253\u5305\u6210\u955c\u50cf)<\/strong> docker commit [options] &lt;\u9700\u6253\u5305\u7684\u5bb9\u5668\u540d&gt; &lt;\u955c\u50cf\u540d&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>options\u53ca\u5176\u5b83\u53c2\u6570\u4f5c\u7528\uff1a\n<strong> -a &lt;\u4f5c\u8005\u540d&gt;<\/strong>\uff0c\u6307\u5b9a\u955c\u50cf\u4f5c\u8005\n<strong> -c &lt;List&gt;<\/strong>\uff0c\u4f7f\u7528dockerfile\u6765\u521b\u5efa\u955c\u50cf\n<strong> -m &lt;\u4fe1\u606f&gt;<\/strong>\uff0c\u672c\u6b21\u6253\u5305\u7684\u76f8\u5173\u4fe1\u606f\n<strong> -p<\/strong>\uff0c\u6253\u5305\u65f6\u6682\u505c\u5bb9\u5668\u8fd0\u884c\n <strong>&lt;\u9700\u6253\u5305\u7684\u5bb9\u5668\u540d&gt;<\/strong>\uff0c\u6253\u5305\u7684\u76ee\u6807\u5bb9\u5668\n <strong>&lt;\u955c\u50cf\u540d&gt;<\/strong>\uff0c\u6253\u5305\u540e\u955c\u50cf\u7684\u540d\u5b57<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>2.14 \u5c01\u88c5\u5df2\u6253\u5305\u7684\u5bb9\u5668<\/strong> docker save [options] [\u6253\u5305\u540e\u6587\u4ef6\u540d.\u540e\u7f00] &lt;\u9700\u8981\u6253\u5305\u7684\u955c\u50cf\u540d&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>options\u53ca\u5176\u5b83\u53c2\u6570\u4f5c\u7528\uff1a\n <strong>-o &lt;\u6587\u4ef6\u540d&gt;<\/strong>\uff0c\u6307\u5b9a\u6587\u4ef6\u540d\u79f0\n<strong>\u4f8b\u5982\uff1a<\/strong>docker save -o myapp.tar myapp\uff0c\u6ce8\u610f\u8fd9\u91cc\u7684\u6587\u4ef6\u540d\u9700\u8981\u5c0f\u5199\uff01<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>2.15 \u52a0\u8f7d\u6253\u5305\u7684\u5bb9\u5668<\/strong> docker load [options]  &lt;\u5df2\u6253\u5305\u7684\u955c\u50cf\u6587\u4ef6\u540d&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code has-normal-font-size\"><code>options\u53ca\u5176\u5b83\u53c2\u6570\u4f5c\u7528\uff1a\n<strong> -i<\/strong>\uff0c\u6307\u5b9a\u6587\u4ef6\u540d<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>2.16 \u5377\u64cd\u4f5c <\/strong>docker volume [command]<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>command\u53ca\u5176\u4f5c\u7528\uff1a\n<strong> ls<\/strong>\uff0c\u67e5\u770b\u6240\u6709\u5377\n <strong>create &lt;\u5377\u540d&gt;<\/strong>\uff0c\u521b\u5efa\u4e00\u4e2a\u5377\n <strong>inspect &lt;\u5377\u540d&gt;<\/strong>\uff0c\u67e5\u770b\u67d0\u4e2a\u5377\u7684\u8be6\u60c5<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>2.17 \u67e5\u770bdocker\u5bf9\u8c61\u8be6\u7ec6\u4fe1\u606f <\/strong>docker inspect [options] &lt;\u540d\u79f0\/ID&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>options\u53ca\u5176\u4f5c\u7528\uff1a\n <strong>-type<\/strong>\uff0c\u8fd4\u56de\u6307\u5b9a\u7c7b\u578b\u7684\u5bf9\u8c61\u4fe1\u606f\uff0c\u53ef\u9009\u7c7b\u578b(container\u3001image\u3001network\u3001volume)\n<strong>\u4f8b\u5982\uff1a<\/strong>docker network inspect -&gt;\u67e5\u770bdocker\u7f51\u7edc\u8be6\u60c5<\/code><\/pre>\n\n\n\n<p style=\"font-size:28px\"><strong>3.\u5206\u4eab\u955c\u50cf<\/strong><\/p>\n\n\n\n<p style=\"font-size:20px\"><strong>3.1<\/strong> <strong>\u767b\u5f55hub\u8d26\u53f7<\/strong> docker login<\/p>\n\n\n\n<p style=\"font-size:20px\"><strong>3.2<\/strong> <strong>\u7ed9\u955c\u50cf\u6dfb\u52a0\u6807\u7b7e<\/strong> docker tag &lt;\u539f\u955c\u50cf\u540d&lt;:\u7248\u672c\u540d&gt;&gt; &lt;\u65b0\u6807\u8bb0\u540d&lt;:\u7248\u672c\u540d&gt;&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code has-normal-font-size\"><code>\u7ed9\u955c\u50cf\u6807\u8bb0\u4e0d\u540c\u7248\u672c\u6216\u8005\u522b\u540d\uff0c\u4fbf\u4e8e\u5f52\u5165\u7279\u5b9a\u4ed3\u5e93\n<strong>\u4f8b\u5982\uff1a<\/strong>docker tag mynginx:v1.0 runseasy\/mynginx:latest<\/code><\/pre>\n\n\n\n<p style=\"font-size:20px\"><strong>3.2 \u63a8\u9001\u81f3login\u8d26\u6237<\/strong> dockers push &lt;\u955c\u50cf\u540d:\u7248\u672c\u53f7&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code has-normal-font-size\"><code>\u6700\u597d\u4e3atag\u540e\u7684\u540d\u79f0\uff0c\u4fbf\u4e8e\u7ba1\u7406\n\u7248\u672c\u540d\u53ef\u4ee5\u4e3a:latest\uff0c\u4e5f\u5c31\u662f\u6307\u5b9a\u4ed6\u4e3a\u6700\u65b0\u7248\u672c\uff0c\u4fbf\u4e8e\u4e0b\u8f7d\uff08\u65e0\u9700\u6307\u5b9a\u7248\u672c\u53f7\uff09<\/code><\/pre>\n\n\n\n<p style=\"font-size:28px\"><strong>4.\u81ea\u5b9a\u4e49\u7f51\u7edc<\/strong><\/p>\n\n\n\n<p style=\"font-size:20px\"><strong>4.1 \u81ea\u5b9a\u4e49\u7f51\u7edc\u76f8\u5173<\/strong> docker network &lt;commands&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>command\u53ca\u5176\u4f5c\u7528\uff1a\n<strong> ls<\/strong>\uff0c\u67e5\u770b\u6240\u6709\u7f51\u7edc\n<strong> create &lt;name&gt;<\/strong>\uff0c\u521b\u5efa\u4e00\u4e2a\u7f51\u7edc\n\u5bb9\u5668\u52a0\u5165\u540c\u4e00\u7f51\u7edc\u540e(\u53c2\u80032.4\u4e2d--network\u53c2\u6570)\uff0c\u5bb9\u5668\u540d=\u8bbf\u95ee\u7f51\u7edc\u57df\u540d\uff0c\n<strong>\u4f8b\u5982\uff1a<\/strong>docker exec -it app1 bash\u4e0b\uff0c\u53ef\u4ee5\u7528curl http:\/\/app02:80\u8bbf\u95ee\u5230app02\u7684\u6570\u636e\uff0c\u6ce8\u610f\u8fd9\u91cc\u7684\u7aef\u53e3\u662f\u5bb9\u5668\u7684\u5185\u90e8\u7aef\u53e3<\/code><\/pre>\n\n\n\n<p style=\"font-size:28px\"><strong>5.compose.yaml\u6587\u4ef6\u7f16\u5199\u53ca\u5e94\u7528<\/strong><\/p>\n\n\n\n<p><strong>\u8be6\u7ec6\u53c2\u8003\uff1a<\/strong><a href=\"https:\/\/docs.docker.com\/reference\/cli\/docker\/compose\/\">docker compose | Docker Docs<\/a><\/p>\n\n\n\n<p style=\"font-size:20px\"><strong>5.1<\/strong> compose.yaml\u7f16\u5199\u89c4\u8303<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized is-style-default\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/a1d3887a20beda732d41f8ce641d387d.png\" alt=\"\" class=\"wp-image-828\" width=\"812\" height=\"723\" srcset=\"https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/a1d3887a20beda732d41f8ce641d387d.png 812w, https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/a1d3887a20beda732d41f8ce641d387d-300x267.png 300w, https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/a1d3887a20beda732d41f8ce641d387d-768x684.png 768w, https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/a1d3887a20beda732d41f8ce641d387d-280x249.png 280w\" sizes=\"(max-width: 812px) 100vw, 812px\" \/><\/figure>\n\n\n\n<p style=\"font-size:20px\"><strong>5.2<\/strong> docker compose &lt;commands&gt; [options] &lt;service&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>commands\u7528\u6cd5:\n <strong>up<\/strong>\uff0c\u4ece&lt;service&gt;\u4e2d\u6784\u5efa(build)-&gt;\u521b\u5efa(create)-&gt;\u542f\u52a8(start)\u4e00\u4e2a\u5bb9\u5668\uff0c\u4ece\u65e0\u5230\u6709\u521b\u5efa\n <strong>down<\/strong> \uff0c\u505c\u6b62\u5e76\u5220\u9664\u5bb9\u5668\u3001\u7f51\u7edc\uff0c\u4f7f\u7528--rmi all -v\u53ef\u4ee5\u8fde\u5e26\u5220\u9664\u5377\n <strong>stop<\/strong> \uff0c\u505c\u6b62\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1\n<strong> ls<\/strong>\uff0c\u67e5\u770b\u6b63\u5728\u8fd0\u884c\u7684compose\u9879\u76ee\noptions\u7528\u6cd5\uff1a\n<strong> -f<\/strong>\uff0c\u6307\u5b9a\u6587\u4ef6\u540d\uff0c\u4e0d\u6307\u5b9a\u5219\u81ea\u52a8\u5339\u914d\u540d\u4e3acompose.yaml\u7684\u6587\u4ef6\n<strong> -d<\/strong>\uff0c\u540e\u53f0\u542f\u52a8\ntips\uff1a\n \u6267\u884c\u540c\u4e00\u4e2acompose\u6587\u4ef6\uff0cdocker\u4f1a\u8bc6\u522b\u6587\u4ef6\u4e2d\u88ab\u4fee\u6539\u7684\u5185\u5bb9\u9009\u62e9\u6027\u8fd0\u884c\uff0c\u4e0d\u4f1a\u5168\u90e8\u91cd\u65b0\u8fd0\u884c<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized is-style-default\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-7.png\" alt=\"\" class=\"wp-image-835\" width=\"507\" height=\"144\" srcset=\"https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-7.png 507w, https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-7-300x85.png 300w, https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-7-280x80.png 280w\" sizes=\"(max-width: 507px) 100vw, 507px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p style=\"font-size:28px\"><strong>6.DockerFile<\/strong><\/p>\n\n\n\n<p style=\"font-size:20px\"><strong>6.1<\/strong> DockerFile\u91cc\u9700\u8981\u5305\u542b\u57fa\u7840\u73af\u5883\u3001\u8f6f\u4ef6\u5305\u3001\u542f\u52a8\u547d\u4ee4\u4e09\u4e2a\u5185\u5bb9<\/p>\n\n\n\n<p style=\"font-size:20px\"><strong>6.2<\/strong> DockerFile\u6307\u4ee4<\/p>\n\n\n\n<p>\u8be6\u7ec6\u53c2\u8003\uff1a<a href=\"https:\/\/docs.docker.com\/reference\/dockerfile\/\">Dockerfile reference | Docker Docs<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"276\" height=\"390\" src=\"https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-8.png\" alt=\"\" class=\"wp-image-866\" srcset=\"https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-8.png 276w, https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-8-212x300.png 212w\" sizes=\"(max-width: 276px) 100vw, 276px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"486\" height=\"113\" src=\"https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-11.png\" alt=\"\" class=\"wp-image-878\" srcset=\"https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-11.png 486w, https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-11-300x70.png 300w, https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-11-280x65.png 280w\" sizes=\"(max-width: 486px) 100vw, 486px\" \/><\/figure>\n\n\n\n<p style=\"font-size:20px\"><strong>6.3 \u4f7f\u7528dockerfile\u6784\u5efa\u955c\u50cf<\/strong> docker build -f &lt;filename&gt; -t &lt;name&gt; .<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u533a\u522b\u4e8edocker commi\u5c06\u5bb9\u5668\u6253\u5305\u6210\u955c\u50cf\uff0cdocker build\u662f\u5c06\u4e00\u4e2a\u5916\u90e8\u529f\u80fd\u6a21\u5757\u5236\u4f5c\u6210\u955c\u50cf\n\u53c2\u6570\u4ecb\u7ecd\uff1a\n<strong> -f\uff0c<\/strong>\u6307\u5b9adockerfile\u6587\u4ef6\uff0c\u4e0d\u4f7f\u7528\u6b64\u53c2\u6570\u5219\u81ea\u52a8\u5339\u914d\u540d\u4e3aDockerfile\u7684\u6587\u4ef6\n<strong> -t\uff0c<\/strong>\u540c--tag\uff0c\u6307\u5b9a\u5236\u4f5c\u540e\u7684\u955c\u50cf\u540d\n<strong> .\uff0c<\/strong>\u540c.\/\uff0c\u6307\u5b9a\u6784\u5efa\u7684\u4e0a\u4e0b\u6587\u76ee\u5f55\u4e3a\u5f53\u524d\u76ee\u5f55<\/code><\/pre>\n\n\n\n<p>\u8fd0\u884cdockerfile\u6784\u5efa\u955c\u50cf\u793a\u4f8b\u2193\uff1a\u5185\u90e8\u7aef\u53e3\u4e3aEXPOSE\u66b4\u9732\u7aef\u53e3<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"548\" height=\"23\" src=\"https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-12.png\" alt=\"\" class=\"wp-image-883\" srcset=\"https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-12.png 548w, https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-12-300x13.png 300w, https:\/\/awamyy.top\/wp-content\/uploads\/2025\/04\/image-12-280x12.png 280w\" sizes=\"(max-width: 548px) 100vw, 548px\" \/><\/figure>\n\n\n\n<p>6.4 \u5206\u5c42\u5b58\u50a8\u673a\u5236<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u5b89\u88c5docker\u53ef\u53c2\u7167\u5b98\u65b9\u6587\u6863 \u8be6\u7ec6\u53c2\u8003\uff1aIn \u2026<\/p>\n","protected":false},"author":1,"featured_media":633,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[27,1],"tags":[28],"_links":{"self":[{"href":"https:\/\/awamyy.top\/index.php?rest_route=\/wp\/v2\/posts\/631"}],"collection":[{"href":"https:\/\/awamyy.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/awamyy.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/awamyy.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/awamyy.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=631"}],"version-history":[{"count":213,"href":"https:\/\/awamyy.top\/index.php?rest_route=\/wp\/v2\/posts\/631\/revisions"}],"predecessor-version":[{"id":893,"href":"https:\/\/awamyy.top\/index.php?rest_route=\/wp\/v2\/posts\/631\/revisions\/893"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/awamyy.top\/index.php?rest_route=\/wp\/v2\/media\/633"}],"wp:attachment":[{"href":"https:\/\/awamyy.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/awamyy.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/awamyy.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}