{"id":424,"date":"2022-08-17T15:58:52","date_gmt":"2022-08-17T07:58:52","guid":{"rendered":"https:\/\/aaaahui.top\/?p=424"},"modified":"2022-08-17T15:59:12","modified_gmt":"2022-08-17T07:59:12","slug":"docker_use","status":"publish","type":"post","link":"https:\/\/ahui.blog\/index.php\/2022\/08\/17\/docker_use\/","title":{"rendered":"Docker\u4f7f\u7528\u901f\u67e5\u624b\u518c"},"content":{"rendered":"<p><strong>\u524d\u8a00\uff1a\u590d\u4e60\u4e00\u4e0b\uff0c\u987a\u4fbf\u8bb0\u5f55\u4e00\u4e0b\uff0c\u65b9\u4fbf\u4ee5\u540e\u518d\u67e5\u4f7f\u7528\u65b9\u6cd5\u3002<\/strong><\/p>\n<h2>Docker\u5b89\u88c5\u3001\u914d\u7f6e\u4ee5\u53ca\u66f4\u6362\u955c\u50cf\u6e90<\/h2>\n<p>docker\u5b89\u88c5\uff1a<a href=\"https:\/\/www.runoob.com\/docker\/centos-docker-install.html\">https:\/\/www.runoob.com\/docker\/centos-docker-install.html<\/a><\/p>\n<p>\u955c\u50cf\u52a0\u901f\uff1a<\/p>\n<p>Ubuntu14.04\u3001Debian7Wheezy \u7f16\u8f91\u6587\u4ef6\uff1a\/etc\/default\/docker<\/p>\n<p>\u7f16\u8f91\u5b8c\u6210\u540e\u91cd\u542f\u547d\u4ee4\uff1asudo service docker restart<\/p>\n<pre><code>DOCKER_OPTS=&quot;--registry-mirror=https:\/\/registry.docker-cn.com&quot;<\/code><\/pre>\n<p>Ubuntu16.04+\u3001Debian8+\u3001CentOS7 \u7f16\u8f91\u6587\u4ef6\uff1a\/etc\/docker\/daemon.json<\/p>\n<p>\u7f16\u8f91\u5b8c\u6210\u540e\u91cd\u542f\u547d\u4ee4\uff1asudo\u00a0systemctl daemon-reload     sudo\u00a0systemctl restart docker<\/p>\n<pre><code>{&quot;registry-mirrors&quot;:[&quot;https:\/\/reg-mirror.qiniu.com\/&quot;]}<\/code><\/pre>\n<p>\u68c0\u67e5\u52a0\u901f\u5668\u662f\u5426\u751f\u6548\uff1a<\/p>\n<p>$ docker info<br \/>\nRegistry Mirrors:<br \/>\n<a href=\"https:\/\/reg-mirror.qiniu.com\">https:\/\/reg-mirror.qiniu.com<\/a> <\/p>\n<p>\u914d\u7f6e\u5bb9\u5668\u7684DNS\u00a0(\/etc\/docker\/daemon.json)\uff1a<\/p>\n<pre><code class=\"language-json\">{\n  &quot;dns&quot; : [\n    &quot;114.114.114.114&quot;,\n    &quot;8.8.8.8&quot;\n  ]\n}<\/code><\/pre>\n<p>\u624b\u52a8\u6307\u5b9a\u5bb9\u5668\u7684DNS\u914d\u7f6e\uff1adocker run -it --rm -h host_ubuntu  --dns=114.114.114.114 --dns-search=test.com ubuntu<\/p>\n<ul>\n<li>\n<p>--rm\uff1a\u5bb9\u5668\u9000\u51fa\u65f6\u81ea\u52a8\u6e05\u7406\u5bb9\u5668\u5185\u90e8\u7684\u6587\u4ef6\u7cfb\u7edf\u3002<\/p>\n<\/li>\n<li>\n<p>-h HOSTNAME \u6216\u8005 --hostname=HOSTNAME\uff1a \u8bbe\u5b9a\u5bb9\u5668\u7684\u4e3b\u673a\u540d\uff0c\u5b83\u4f1a\u88ab\u5199\u5230\u5bb9\u5668\u5185\u7684 \/etc\/hostname \u548c \/etc\/hosts\u3002<\/p>\n<\/li>\n<li>\n<p>--dns=IP_ADDRESS\uff1a \u6dfb\u52a0 DNS \u670d\u52a1\u5668\u5230\u5bb9\u5668\u7684 \/etc\/resolv.conf \u4e2d\uff0c\u8ba9\u5bb9\u5668\u7528\u8fd9\u4e2a\u670d\u52a1\u5668\u6765\u89e3\u6790\u6240\u6709\u4e0d\u5728 \/etc\/hosts \u4e2d\u7684\u4e3b\u673a\u540d\u3002<\/p>\n<\/li>\n<li>\n<p>--dns-search=DOMAIN\uff1a \u8bbe\u5b9a\u5bb9\u5668\u7684\u641c\u7d22\u57df\uff0c\u5f53\u8bbe\u5b9a\u641c\u7d22\u57df\u4e3a .example.com \u65f6\uff0c\u5728\u641c\u7d22\u4e00\u4e2a\u540d\u4e3a host \u7684\u4e3b\u673a\u65f6\uff0cDNS \u4e0d\u4ec5\u641c\u7d22 host\uff0c\u8fd8\u4f1a\u641c\u7d22 host.example.com\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u67e5\u770b\u5bb9\u5668\u7684DNS\u662f\u5426\u751f\u6548\uff1adocker run -it --rm  ubuntu  cat etc\/resolv.conf<\/p>\n<h2>\u57fa\u672c\u547d\u4ee4<\/h2>\n<p>\u62c9\u53d6\u955c\u50cf\uff1adocker pull ubuntu<\/p>\n<p>\u542f\u52a8\u5bb9\u5668\uff1adocker run -it ubuntu \/bin\/bash<\/p>\n<ul>\n<li>\n<p>-d:\u8ba9\u5bb9\u5668\u5728\u540e\u53f0\u8fd0\u884c\u3002<\/p>\n<\/li>\n<li>\n<p>-P:\u5c06\u5bb9\u5668\u5185\u90e8\u4f7f\u7528\u7684\u7f51\u7edc\u7aef\u53e3\u968f\u673a\u6620\u5c04\u5230\u6211\u4eec\u4f7f\u7528\u7684\u4e3b\u673a\u4e0a\u3002<\/p>\n<\/li>\n<li>\n<p>-p:5000:5000 \u6307\u5b9a\u5bb9\u5668\u5185\u8981\u6620\u5c04\u7684\u7aef\u53e3\uff0c\u524d\u9762\u76845000\u4e3a\u4e3b\u673a\u7aef\u53e3\uff0c\u540e\u9762\u7684\u4e3a\u7ed1\u5b9a\u7684\u5bb9\u5668\u7aef\u53e3\uff0c\u4e5f\u53ef\u4ee5\u6307\u5b9a\u7ed1\u5b9a\u7684\u7f51\u7edc\u5730\u5740\u5982-p 127.0.0.1:5000:5000\uff0c\u4e5f\u53ef\u4ee5\u7ed1\u5b9audp\u7aef\u53e3\uff0c\u5728\u7aef\u53e3\u540e\u9762\u52a0\u4e0a\/udp\uff0c\u5982-p 127.0.0.1:5000:5000\/udp<\/p>\n<\/li>\n<\/ul>\n<p>\u9000\u51fa\u5bb9\u5668\uff1aexit<\/p>\n<p>\u67e5\u770b\u6b63\u5728\u8fd0\u884c\u7684\u5bb9\u5668\uff1adocker ps<\/p>\n<p>\u67e5\u770b\u6700\u540e\u4e00\u4e2a\u521b\u5efa\u7684\u5bb9\u5668\uff1adocker ps -l<\/p>\n<p>\u67e5\u770b\u6240\u6709\u5bb9\u5668\uff1adocker ps -a<\/p>\n<p>\u505c\u6b62\u4e00\u4e2a\u5bb9\u5668\uff1adocker stop b750bbbcfd88<\/p>\n<p>\u542f\u52a8\u4e00\u4e2a\u5df2\u505c\u6b62\u7684\u5bb9\u5668\uff1adocker start b750bbbcfd88<\/p>\n<p>\u91cd\u542f\u4e00\u4e2a\u5bb9\u5668\uff1adocker restart b750bbbcfd88<\/p>\n<p>\u540e\u53f0\u8fd0\u884c\u4e00\u4e2a\u5bb9\u5668\uff1adocker run -itd --name ubuntu-test ubuntu \/bin\/bash<\/p>\n<p>\u8fdb\u5165\u5bb9\u56681\uff1adocker attach 1e560fca3906 \u8fd9\u6837\u8fdb\u53bb\u9000\u51fa\u6765\u4f1a\u5bfc\u81f4\u5bb9\u5668\u505c\u6b62<\/p>\n<p>\u8fdb\u5165\u5bb9\u56682\uff1adocker exec -it 243c32535da7 \/bin\/bash \u8fd9\u6837\u8fdb\u53bb\u9000\u51fa\u6765\u4e0d\u4f1a\u5bfc\u81f4\u5bb9\u5668\u505c\u6b62<\/p>\n<p>\u5bfc\u51fa\u5bb9\u5668\uff1adocker export 1e560fca3906 &gt; ubuntu.tar<\/p>\n<p>\u5bfc\u5165\u5bb9\u5668\uff1acat docker\/ubuntu.tar | docker import - test\/ubuntu:v1<\/p>\n<p>\u901a\u8fc7URL\u5bfc\u5165\u5bb9\u5668\uff1adocker import <a href=\"http:\/\/example.com\/exampleimage.tgz\">http:\/\/example.com\/exampleimage.tgz<\/a> example\/imagerepo<\/p>\n<p>\u5220\u9664\u5bb9\u5668\uff1adocker rm -f 1e560fca3906<\/p>\n<p>\u6e05\u7406\u6240\u6709\u5904\u4e8e\u4e2d\u6b62\u72b6\u6001\u7684\u5bb9\u5668\uff1adocker container prune<\/p>\n<p>\u67e5\u770b\u5bb9\u5668\u7aef\u53e3\u7684\u6620\u5c04\u60c5\u51b5\uff1adocker port bf08b7f2cd89<\/p>\n<p>\u67e5\u770b\u5bb9\u5668\u5185\u7684\u65e5\u5fd7\uff1adocker logs -f bf08b7f2cd89<\/p>\n<p>\u67e5\u770b\u5bb9\u5668\u7684\u8fdb\u7a0b\uff1adocker top bf08b7f2cd89<\/p>\n<p>\u67e5\u770b\u5bb9\u5668\u7684\u5e95\u5c42\u4fe1\u606f\uff1adocker inspect bf08b7f2cd89<\/p>\n<h2>\u955c\u50cf\u76f8\u5173<\/h2>\n<p>\u5217\u51fa\u672c\u5730\u4e3b\u673a\u4e0a\u7684\u955c\u50cf\uff1adocker images<\/p>\n<p>\u4f7f\u7528\u955c\u50cf\u6765\u8fd0\u884c\u5bb9\u5668\uff1adocker run -t -i ubuntu:15.10 \/bin\/bash<\/p>\n<ul>\n<li><strong>-i<\/strong>: \u4ea4\u4e92\u5f0f\u64cd\u4f5c\u3002<\/li>\n<li><strong>-t<\/strong>: \u7ec8\u7aef\u3002<\/li>\n<li><strong>ubuntu:15.10<\/strong>: \u8fd9\u662f\u6307\u7528 ubuntu 15.10 \u7248\u672c\u955c\u50cf\u4e3a\u57fa\u7840\u6765\u542f\u52a8\u5bb9\u5668\u3002<\/li>\n<li><strong>\/bin\/bash<\/strong>\uff1a\u653e\u5728\u955c\u50cf\u540d\u540e\u7684\u662f\u547d\u4ee4\uff0c\u8fd9\u91cc\u6211\u4eec\u5e0c\u671b\u6709\u4e2a\u4ea4\u4e92\u5f0f Shell\uff0c\u56e0\u6b64\u7528\u7684\u662f \/bin\/bash\u3002<\/li>\n<\/ul>\n<p>\u67e5\u627e\u955c\u50cf\uff1adocker search httpd<\/p>\n<p>\u62c9\u53bb\u5bf9\u5e94\u7248\u672c\u955c\u50cf\uff1adocker pull ubuntu:13.10<\/p>\n<p>\u5220\u9664\u955c\u50cf\uff1adocker rmi hello-world\u00a0\u00a0\u00a0\u00a0\u6ce8\uff1a\u8981\u5220\u9664\u955c\u50cf\u9700\u8981\u5148\u505c\u6b62\u76f8\u5e94\u5bb9\u5668\uff0c\u518d\u5220\u9664\u8be5\u955c\u50cf<\/p>\n<h3>\u521b\u5efa\u955c\u50cf<\/h3>\n<h4>\u66f4\u65b0\u65e7\u955c\u50cf<\/h4>\n<ul>\n<li>1\u3001\u4ece\u5df2\u7ecf\u521b\u5efa\u7684\u5bb9\u5668\u4e2d\u66f4\u65b0\u955c\u50cf\uff0c\u5e76\u4e14\u63d0\u4ea4\u8fd9\u4e2a\u955c\u50cf<\/li>\n<li>2\u3001\u4f7f\u7528\u00a0Dockerfile\u00a0\u6307\u4ee4\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u955c\u50cf<\/li>\n<\/ul>\n<p>\u4e00\u3001\u5728\u8fd0\u884c\u7684\u5bb9\u5668\u5185\u4f7f\u7528\uff1a<strong>apt-get update<\/strong>\u547d\u4ee4\u8fdb\u884c\u66f4\u65b0<\/p>\n<p>\u4e8c\u3001exit\u9000\u51fa\u5bb9\u5668<\/p>\n<p>\u4e09\u3001docker commit -m=&quot;test&quot; -a=&quot;aaaahui&quot; e218edb10161 aaaahui\/ubuntu:v2<\/p>\n<ul>\n<li>\n<p><strong>-m:<\/strong>\u00a0\u63d0\u4ea4\u7684\u63cf\u8ff0\u4fe1\u606f<\/p>\n<\/li>\n<li>\n<p><strong>-a:<\/strong>\u00a0\u6307\u5b9a\u955c\u50cf\u4f5c\u8005<\/p>\n<\/li>\n<li>\n<p><strong>e218edb10161\uff1a<\/strong>\u5bb9\u5668 ID<\/p>\n<\/li>\n<li>\n<p><strong>aaaahui\/ubuntu:v2:<\/strong>\u00a0\u6307\u5b9a\u8981\u521b\u5efa\u7684\u76ee\u6807\u955c\u50cf\u540d<\/p>\n<\/li>\n<\/ul>\n<p>\u56db\u3001\u6b64\u65f6\u4f7f\u7528docker images\u53ef\u4ee5\u67e5\u770b\u521b\u5efa\u7684\u955c\u50cf<\/p>\n<h4>\u6784\u5efa\u5168\u65b0\u955c\u50cf<\/h4>\n<p>\u7f16\u5199Dockerfile<\/p>\n<pre><code class=\"language-dockerfile\">FROM    centos:6.7\nMAINTAINER      Fisher &quot;fisher@sudops.com&quot;\n\nRUN     \/bin\/echo &#039;root:123456&#039; |chpasswd\nRUN     useradd runoob\nRUN     \/bin\/echo &#039;runoob:123456&#039; |chpasswd\nRUN     \/bin\/echo -e &quot;LANG=\\&quot;en_US.UTF-8\\&quot;&quot; &gt;\/etc\/default\/local\nEXPOSE  22\nEXPOSE  80\nCMD     \/usr\/sbin\/sshd -D<\/code><\/pre>\n<p>\u6784\u5efa\u955c\u50cf\u547d\u4ee4\uff1adocker build -t runoob\/centos:6.7 .<\/p>\n<ul>\n<li>\n<p><strong>-t<\/strong>\u00a0\uff1a\u6307\u5b9a\u8981\u521b\u5efa\u7684\u76ee\u6807\u955c\u50cf\u540d<\/p>\n<\/li>\n<li>\n<p><strong>.<\/strong>\u00a0\uff1aDockerfile\u00a0\u6587\u4ef6\u6240\u5728\u76ee\u5f55\uff0c\u53ef\u4ee5\u6307\u5b9aDockerfile\u00a0\u7684\u7edd\u5bf9\u8def\u5f84<\/p>\n<\/li>\n<\/ul>\n<p>\u7136\u540e\u4f7f\u7528docker images\u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u672c\u5730\u5bb9\u5668<\/p>\n<p>\u8bbe\u7f6e\u955c\u50cf\u6807\u7b7e\uff1adocker tag 860c279d2fec runoob\/centos:dev<\/p>\n<h2>Docker\u5bb9\u5668\u8fde\u63a5<\/h2>\n<h5>\u65b0\u5efa\u7f51\u7edc<\/h5>\n<p>docker network create -d bridge test-net<\/p>\n<p>-d\uff1a\u53c2\u6570\u6307\u5b9a Docker \u7f51\u7edc\u7c7b\u578b\uff0c\u6709 bridge\u3001overlay\u3002<\/p>\n<h5>\u8fde\u63a5\u5bb9\u5668<\/h5>\n<p>\u8fd0\u884c\u4e00\u4e2a\u65b0\u5bb9\u5668\u5e76\u8fde\u63a5\u5230test-net\u7f51\u7edc\uff1a<\/p>\n<p>docker run -itd --name test1 --network test-net ubuntu \/bin\/bash<\/p>\n<p>\u518d\u8fd0\u884c\u4e00\u4e2a\u5bb9\u5668\u52a0\u5165\u5230test-net\u7f51\u7edc\uff1a<\/p>\n<p>docker run -itd --name test2 --network test-net ubuntu \/bin\/bash<\/p>\n<h2>Docker\u4ed3\u5e93\u7ba1\u7406<\/h2>\n<p><strong>\u4ed3\u5e93\uff08Repository\uff09\u662f\u96c6\u4e2d\u5b58\u653e\u955c\u50cf\u7684\u5730\u65b9\uff0cdocker\u5b98\u65b9\u7684\u6709dockerhub<\/strong><\/p>\n<p>dockerhub\u767b\u5f55\uff1adocker login<\/p>\n<p>dockerhub\u9000\u51fa\uff1adocker logout<\/p>\n<h5>\u767b\u5f55\u540e\u5411\u4ed3\u5e93\u63a8\u9001\u955c\u50cf<\/h5>\n<p>\u7ed9\u81ea\u5df1\u7684\u955c\u50cf\u8bbe\u7f6e\u6807\u7b7e\uff1adocker tag ununtu:18.04 aaaahui\/ununtu:18.04<\/p>\n<p>\u67e5\u770b\u672c\u5730\u955c\u50cf\uff1adocker image ls = docker images<\/p>\n<h2>Docker Dockerfile<\/h2>\n<p>Dockerfile\u662f\u5b9a\u5236\u955c\u50cf\u7684\u6587\u672c\u6587\u4ef6\uff0c\u91cc\u9762\u5305\u542b\u6784\u5efa\u955c\u50cf\u6240\u9700\u7684\u6307\u4ee4\u548c\u8bf4\u660e\u3002<\/p>\n<p>\u4f8b\u5b50\uff1a\u5b9a\u5236\u4e00\u4e2anginx\u955c\u50cf<\/p>\n<p>\u65b0\u5efanginx_image\u6587\u4ef6\u5939\uff0c\u5728\u91cc\u9762\u65b0\u5efaDockerfile\u6587\u4ef6\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9<\/p>\n<pre><code class=\"language-dockerfile\">FROM nginx\nRUN echo &#039;\u8fd9\u662f\u4e00\u4e2a\u672c\u5730\u6784\u5efa\u7684nginx\u955c\u50cf&#039; &gt; \/usr\/share\/nginx\/html\/index.html<\/code><\/pre>\n<p><strong>FROM<\/strong>\uff1a\u5b9a\u5236\u7684\u955c\u50cf\u90fd\u662f\u57fa\u4e8e FROM \u7684\u955c\u50cf\uff0c\u8fd9\u91cc\u7684 nginx \u5c31\u662f\u5b9a\u5236\u9700\u8981\u7684\u57fa\u7840\u955c\u50cf\u3002\u540e\u7eed\u7684\u64cd\u4f5c\u90fd\u662f\u57fa\u4e8e nginx\u3002<\/p>\n<p><strong>RUN<\/strong>\uff1a\u7528\u4e8e\u6267\u884c\u540e\u9762\u8ddf\u7740\u7684\u547d\u4ee4\u884c\u547d\u4ee4\u3002\u6709\u4ee5\u4e0b\u4fe9\u79cd\u683c\u5f0f\uff1a<\/p>\n<p>shell \u683c\u5f0f\uff1a<\/p>\n<pre><code>RUN &lt;\u547d\u4ee4\u884c\u547d\u4ee4&gt;\n\n#&lt;\u547d\u4ee4\u884c\u547d\u4ee4&gt; \u7b49\u540c\u4e8e\uff0c\u5728\u7ec8\u7aef\u64cd\u4f5c\u7684 shell \u547d\u4ee4\u3002\n<\/code><\/pre>\n<p>exec \u683c\u5f0f\uff1a<\/p>\n<pre><code>RUN [&quot;\u53ef\u6267\u884c\u6587\u4ef6&quot;, &quot;\u53c2\u65701&quot;, &quot;\u53c2\u65702&quot;]\n\n\u4f8b\u5982\uff1a\n\nRUN [&quot;.\/test.php&quot;, &quot;dev&quot;, &quot;offline&quot;] \u7b49\u4ef7\u4e8e RUN .\/test.php dev offline\n<\/code><\/pre>\n<p><strong>\u6ce8\u610f\uff1aDockerfile \u7684\u6307\u4ee4\u6bcf\u6267\u884c\u4e00\u6b21\u90fd\u4f1a\u5728 docker \u4e0a\u65b0\u5efa\u4e00\u5c42\u3002\u6240\u4ee5\u8fc7\u591a\u65e0\u610f\u4e49\u7684\u5c42\uff0c\u4f1a\u9020\u6210\u955c\u50cf\u81a8\u80c0\u8fc7\u5927<\/strong><\/p>\n<p>\u521b\u5efa\u4e09\u5c42\uff1a<\/p>\n<pre><code class=\"language-dockerfile\">FROM centos  \nRUN\u00a0yum\u00a0-y\u00a0install\u00a0wget  \nRUN\u00a0wget\u00a0-O\u00a0redis.tar.gz\u00a0&quot;http:\/\/download.redis.io\/releases\/redis-5.0.3.tar.gz&quot;  \nRUN\u00a0tar\u00a0-xvf\u00a0redis.tar.gz<\/code><\/pre>\n<p>\u7b80\u5316\u6210\u4e00\u5c42\uff1a<\/p>\n<pre><code class=\"language-dockerfile\">FROM centos\nRUN yum -y install wget \\\n    &amp;&amp; wget -O redis.tar.gz &quot;http:\/\/download.redis.io\/releases\/redis-5.0.3.tar.gz&quot; \\\n    &amp;&amp; tar -xvf redis.tar.gz<\/code><\/pre>\n<p>\u6784\u5efa\u955c\u50cf\uff1adocker build\u00a0-t\u00a0nginx:v3 .<\/p>\n<ul>\n<li>\n<p>-t:\u6307\u5b9a\u955c\u50cf\u540d\u79f0:\u6807\u7b7e<\/p>\n<\/li>\n<li>\n<p>.:\u4e0a\u4e0b\u6587\u8def\u5f84\uff0c\u8fd9\u91cc\u4f1a\u6253\u5305\u8be5\u6307\u5b9a\u8def\u5f84\u4e0b\u6240\u6709\u7684\u6587\u4ef6\u5230\u65b0\u5efa\u7684\u955c\u50cf\u4e2d\uff0c\u6240\u4ee5\u5728\u6b64\u8def\u5f84\u4e0b\u4e0d\u8981\u653e\u591a\u4f59\u6587\u4ef6\uff0c\u6587\u4ef6\u8fc7\u591a\u4f1a\u9020\u6210\u8fc7\u7a0b\u7f13\u6162\uff0c\u955c\u50cf\u5e9e\u5927\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>Dockerfile\u7684\u5176\u4ed6\u6307\u4ee4<\/h4>\n<blockquote>\n<h5>COPY<\/h5>\n<p>\u590d\u5236\u6307\u4ee4\uff0c\u4ece\u4e0a\u4e0b\u6587\u76ee\u5f55\u4e2d\u590d\u5236\u6587\u4ef6\u6216\u8005\u76ee\u5f55\u5230\u5bb9\u5668\u91cc\u6307\u5b9a\u8def\u5f84\u3002<\/p>\n<p>\u683c\u5f0f\uff1a<\/p>\n<p>COPY [--chown=<user>:<group>] &lt;\u6e90\u8def\u5f841&gt;...  &lt;\u76ee\u6807\u8def\u5f84&gt;<br \/>\nCOPY [--chown=<user>:<group>] [&quot;&lt;\u6e90\u8def\u5f841&gt;&quot;,...  &quot;&lt;\u76ee\u6807\u8def\u5f84&gt;&quot;]<\/p>\n<p><strong>[--chown=<user>:<group>]<\/strong>\uff1a\u53ef\u9009\u53c2\u6570\uff0c\u7528\u6237\u6539\u53d8\u590d\u5236\u5230\u5bb9\u5668\u5185\u6587\u4ef6\u7684\u62e5\u6709\u8005\u548c\u5c5e\u7ec4\u3002<\/p>\n<p><strong>&lt;\u6e90\u8def\u5f84&gt;<\/strong>\uff1a\u6e90\u6587\u4ef6\u6216\u8005\u6e90\u76ee\u5f55\uff0c\u8fd9\u91cc\u53ef\u4ee5\u662f\u901a\u914d\u7b26\u8868\u8fbe\u5f0f\uff0c\u5176\u901a\u914d\u7b26\u89c4\u5219\u8981\u6ee1\u8db3 Go \u7684 filepath.Match \u89c4\u5219\u3002\u4f8b\u5982\uff1a<\/p>\n<p>COPY hom* \/mydir\/<br \/>\nCOPY hom?.txt \/mydir\/<\/p>\n<p><strong>&lt;\u76ee\u6807\u8def\u5f84&gt;<\/strong>\uff1a\u5bb9\u5668\u5185\u7684\u6307\u5b9a\u8def\u5f84\uff0c\u8be5\u8def\u5f84\u4e0d\u7528\u4e8b\u5148\u5efa\u597d\uff0c\u8def\u5f84\u4e0d\u5b58\u5728\u7684\u8bdd\uff0c\u4f1a\u81ea\u52a8\u521b\u5efa\u3002<\/p>\n<h5>ADD<\/h5>\n<p>ADD \u6307\u4ee4\u548c COPY \u7684\u4f7f\u7528\u683c\u7c7b\u4f3c\uff08\u540c\u6837\u9700\u6c42\u4e0b\uff0c\u5b98\u65b9\u63a8\u8350\u4f7f\u7528 COPY\uff09\u3002\u529f\u80fd\u4e5f\u7c7b\u4f3c\uff0c\u4e0d\u540c\u4e4b\u5904\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>ADD \u7684\u4f18\u70b9\uff1a\u5728\u6267\u884c &lt;\u6e90\u6587\u4ef6&gt; \u4e3a tar \u538b\u7f29\u6587\u4ef6\u7684\u8bdd\uff0c\u538b\u7f29\u683c\u5f0f\u4e3a gzip, bzip2 \u4ee5\u53ca xz \u7684\u60c5\u51b5\u4e0b\uff0c\u4f1a\u81ea\u52a8\u590d\u5236\u5e76\u89e3\u538b\u5230 &lt;\u76ee\u6807\u8def\u5f84&gt;\u3002<\/li>\n<li>ADD \u7684\u7f3a\u70b9\uff1a\u5728\u4e0d\u89e3\u538b\u7684\u524d\u63d0\u4e0b\uff0c\u65e0\u6cd5\u590d\u5236 tar \u538b\u7f29\u6587\u4ef6\u3002\u4f1a\u4ee4\u955c\u50cf\u6784\u5efa\u7f13\u5b58\u5931\u6548\uff0c\u4ece\u800c\u53ef\u80fd\u4f1a\u4ee4\u955c\u50cf\u6784\u5efa\u53d8\u5f97\u6bd4\u8f83\u7f13\u6162\u3002\u5177\u4f53\u662f\u5426\u4f7f\u7528\uff0c\u53ef\u4ee5\u6839\u636e\u662f\u5426\u9700\u8981\u81ea\u52a8\u89e3\u538b\u6765\u51b3\u5b9a\u3002<\/li>\n<\/ul>\n<h5>CMD<\/h5>\n<p>\u7c7b\u4f3c\u4e8e RUN \u6307\u4ee4\uff0c\u7528\u4e8e\u8fd0\u884c\u7a0b\u5e8f\uff0c\u4f46\u4e8c\u8005\u8fd0\u884c\u7684\u65f6\u95f4\u70b9\u4e0d\u540c:<\/p>\n<ul>\n<li>CMD \u5728docker run \u65f6\u8fd0\u884c\u3002<\/li>\n<li>RUN \u662f\u5728 docker build\u3002<\/li>\n<\/ul>\n<p><strong>\u4f5c\u7528<\/strong>\uff1a\u4e3a\u542f\u52a8\u7684\u5bb9\u5668\u6307\u5b9a\u9ed8\u8ba4\u8981\u8fd0\u884c\u7684\u7a0b\u5e8f\uff0c\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u675f\uff0c\u5bb9\u5668\u4e5f\u5c31\u7ed3\u675f\u3002CMD \u6307\u4ee4\u6307\u5b9a\u7684\u7a0b\u5e8f\u53ef\u88ab docker run \u547d\u4ee4\u884c\u53c2\u6570\u4e2d\u6307\u5b9a\u8981\u8fd0\u884c\u7684\u7a0b\u5e8f\u6240\u8986\u76d6\u3002<\/p>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u5982\u679c Dockerfile \u4e2d\u5982\u679c\u5b58\u5728\u591a\u4e2a CMD \u6307\u4ee4\uff0c\u4ec5\u6700\u540e\u4e00\u4e2a\u751f\u6548\u3002<\/p>\n<p>\u683c\u5f0f\uff1a<\/p>\n<p>CMD &lt;shell \u547d\u4ee4&gt; CMD [&quot;&lt;\u53ef\u6267\u884c\u6587\u4ef6\u6216\u547d\u4ee4&gt;&quot;,&quot;<param1>&quot;,&quot;<param2>&quot;,...] CMD [&quot;<param1>&quot;,&quot;<param2>&quot;,...]  # \u8be5\u5199\u6cd5\u662f\u4e3a ENTRYPOINT \u6307\u4ee4\u6307\u5b9a\u7684\u7a0b\u5e8f\u63d0\u4f9b\u9ed8\u8ba4\u53c2\u6570<\/p>\n<p>\u63a8\u8350\u4f7f\u7528\u7b2c\u4e8c\u79cd\u683c\u5f0f\uff0c\u6267\u884c\u8fc7\u7a0b\u6bd4\u8f83\u660e\u786e\u3002\u7b2c\u4e00\u79cd\u683c\u5f0f\u5b9e\u9645\u4e0a\u5728\u8fd0\u884c\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u4f1a\u81ea\u52a8\u8f6c\u6362\u6210\u7b2c\u4e8c\u79cd\u683c\u5f0f\u8fd0\u884c\uff0c\u5e76\u4e14\u9ed8\u8ba4\u53ef\u6267\u884c\u6587\u4ef6\u662f sh\u3002<\/p>\n<h5>ENTRYPOINT<\/h5>\n<p>\u7c7b\u4f3c\u4e8e CMD \u6307\u4ee4\uff0c\u4f46\u5176\u4e0d\u4f1a\u88ab docker run \u7684\u547d\u4ee4\u884c\u53c2\u6570\u6307\u5b9a\u7684\u6307\u4ee4\u6240\u8986\u76d6\uff0c\u800c\u4e14\u8fd9\u4e9b\u547d\u4ee4\u884c\u53c2\u6570\u4f1a\u88ab\u5f53\u4f5c\u53c2\u6570\u9001\u7ed9 ENTRYPOINT \u6307\u4ee4\u6307\u5b9a\u7684\u7a0b\u5e8f\u3002<\/p>\n<p>\u4f46\u662f, \u5982\u679c\u8fd0\u884c docker run \u65f6\u4f7f\u7528\u4e86 --entrypoint \u9009\u9879\uff0c\u5c06\u8986\u76d6 ENTRYPOINT \u6307\u4ee4\u6307\u5b9a\u7684\u7a0b\u5e8f\u3002<\/p>\n<p><strong>\u4f18\u70b9<\/strong>\uff1a\u5728\u6267\u884c docker run \u7684\u65f6\u5019\u53ef\u4ee5\u6307\u5b9a ENTRYPOINT \u8fd0\u884c\u6240\u9700\u7684\u53c2\u6570\u3002<\/p>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u5982\u679c Dockerfile \u4e2d\u5982\u679c\u5b58\u5728\u591a\u4e2a ENTRYPOINT \u6307\u4ee4\uff0c\u4ec5\u6700\u540e\u4e00\u4e2a\u751f\u6548\u3002<\/p>\n<p>\u683c\u5f0f\uff1a<\/p>\n<p>ENTRYPOINT [&quot;<executeable>&quot;,&quot;<param1>&quot;,&quot;<param2>&quot;,...]<\/p>\n<p>\u53ef\u4ee5\u642d\u914d CMD \u547d\u4ee4\u4f7f\u7528\uff1a\u4e00\u822c\u662f\u53d8\u53c2\u624d\u4f1a\u4f7f\u7528 CMD \uff0c\u8fd9\u91cc\u7684 CMD \u7b49\u4e8e\u662f\u5728\u7ed9 ENTRYPOINT \u4f20\u53c2\uff0c\u4ee5\u4e0b\u793a\u4f8b\u4f1a\u63d0\u5230\u3002<\/p>\n<p>\u793a\u4f8b\uff1a<\/p>\n<p>\u5047\u8bbe\u5df2\u901a\u8fc7 Dockerfile \u6784\u5efa\u4e86 nginx:test \u955c\u50cf\uff1a<\/p>\n<p>FROM nginx<br \/>\nENTRYPOINT [&quot;nginx&quot;, &quot;-c&quot;] # \u5b9a\u53c2<br \/>\nCMD [&quot;\/etc\/nginx\/nginx.conf&quot;] # \u53d8\u53c2 <\/p>\n<p>1\u3001\u4e0d\u4f20\u53c2\u8fd0\u884c<\/p>\n<p>$ docker run  nginx:test<\/p>\n<p>\u5bb9\u5668\u5185\u4f1a\u9ed8\u8ba4\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u542f\u52a8\u4e3b\u8fdb\u7a0b\u3002<\/p>\n<p>nginx -c \/etc\/nginx\/nginx.conf<\/p>\n<p>2\u3001\u4f20\u53c2\u8fd0\u884c<\/p>\n<p>$ docker run  nginx:test -c \/etc\/nginx\/new.conf<\/p>\n<p>\u5bb9\u5668\u5185\u4f1a\u9ed8\u8ba4\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u542f\u52a8\u4e3b\u8fdb\u7a0b(\/etc\/nginx\/new.conf:\u5047\u8bbe\u5bb9\u5668\u5185\u5df2\u6709\u6b64\u6587\u4ef6)<\/p>\n<p>nginx -c \/etc\/nginx\/new.conf<\/p>\n<h5>ENV<\/h5>\n<p>\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u5b9a\u4e49\u4e86\u73af\u5883\u53d8\u91cf\uff0c\u90a3\u4e48\u5728\u540e\u7eed\u7684\u6307\u4ee4\u4e2d\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<p>\u683c\u5f0f\uff1a<\/p>\n<p>ENV <key> <value><br \/>\nENV <key1>=<value1> <key2>=<value2>...<\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u8bbe\u7f6e NODE_VERSION = 7.2.0 \uff0c \u5728\u540e\u7eed\u7684\u6307\u4ee4\u4e2d\u53ef\u4ee5\u901a\u8fc7 $NODE_VERSION \u5f15\u7528\uff1a<\/p>\n<p>ENV NODE_VERSION 7.2.0<\/p>\n<p>RUN curl -SLO &quot;<a href=\"https:\/\/nodejs.org\/dist\/v$NODE_VERSION\/node-v$NODE_VERSION-linux-x64.tar.xz\">https:\/\/nodejs.org\/dist\/v$NODE_VERSION\/node-v$NODE_VERSION-linux-x64.tar.xz<\/a>&quot; \\  &amp;&amp; curl -SLO &quot;<a href=\"https:\/\/nodejs.org\/dist\/v$NODE_VERSION\/SHASUMS256.txt.asc\">https:\/\/nodejs.org\/dist\/v$NODE_VERSION\/SHASUMS256.txt.asc<\/a>&quot;<\/p>\n<h5>ARG<\/h5>\n<p>\u6784\u5efa\u53c2\u6570\uff0c\u4e0e ENV \u4f5c\u7528\u4e00\u81f4\u3002\u4e0d\u8fc7\u4f5c\u7528\u57df\u4e0d\u4e00\u6837\u3002ARG \u8bbe\u7f6e\u7684\u73af\u5883\u53d8\u91cf\u4ec5\u5bf9 Dockerfile \u5185\u6709\u6548\uff0c\u4e5f\u5c31\u662f\u8bf4\u53ea\u6709 docker build \u7684\u8fc7\u7a0b\u4e2d\u6709\u6548\uff0c\u6784\u5efa\u597d\u7684\u955c\u50cf\u5185\u4e0d\u5b58\u5728\u6b64\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<p>\u6784\u5efa\u547d\u4ee4 docker build \u4e2d\u53ef\u4ee5\u7528 --build-arg &lt;\u53c2\u6570\u540d&gt;=&lt;\u503c&gt; \u6765\u8986\u76d6\u3002<\/p>\n<p>\u683c\u5f0f\uff1a<\/p>\n<p>ARG &lt;\u53c2\u6570\u540d&gt;[=&lt;\u9ed8\u8ba4\u503c&gt;]<\/p>\n<h5>VOLUME<\/h5>\n<p>\u5b9a\u4e49\u533f\u540d\u6570\u636e\u5377\u3002\u5728\u542f\u52a8\u5bb9\u5668\u65f6\u5fd8\u8bb0\u6302\u8f7d\u6570\u636e\u5377\uff0c\u4f1a\u81ea\u52a8\u6302\u8f7d\u5230\u533f\u540d\u5377\u3002<\/p>\n<p>\u4f5c\u7528\uff1a<\/p>\n<ul>\n<li>\u907f\u514d\u91cd\u8981\u7684\u6570\u636e\uff0c\u56e0\u5bb9\u5668\u91cd\u542f\u800c\u4e22\u5931\uff0c\u8fd9\u662f\u975e\u5e38\u81f4\u547d\u7684\u3002<\/li>\n<li>\u907f\u514d\u5bb9\u5668\u4e0d\u65ad\u53d8\u5927\u3002<\/li>\n<\/ul>\n<p>\u683c\u5f0f\uff1a<\/p>\n<p>VOLUME [&quot;&lt;\u8def\u5f841&gt;&quot;, &quot;&lt;\u8def\u5f842&gt;&quot;...]<br \/>\nVOLUME &lt;\u8def\u5f84&gt;<\/p>\n<p>\u5728\u542f\u52a8\u5bb9\u5668 docker run \u7684\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 -v \u53c2\u6570\u4fee\u6539\u6302\u8f7d\u70b9\u3002<\/p>\n<h5>EXPOSE<\/h5>\n<p>\u4ec5\u4ec5\u53ea\u662f\u58f0\u660e\u7aef\u53e3\u3002<\/p>\n<p>\u4f5c\u7528\uff1a<\/p>\n<ul>\n<li>\u5e2e\u52a9\u955c\u50cf\u4f7f\u7528\u8005\u7406\u89e3\u8fd9\u4e2a\u955c\u50cf\u670d\u52a1\u7684\u5b88\u62a4\u7aef\u53e3\uff0c\u4ee5\u65b9\u4fbf\u914d\u7f6e\u6620\u5c04\u3002<\/li>\n<li>\u5728\u8fd0\u884c\u65f6\u4f7f\u7528\u968f\u673a\u7aef\u53e3\u6620\u5c04\u65f6\uff0c\u4e5f\u5c31\u662f docker run -P \u65f6\uff0c\u4f1a\u81ea\u52a8\u968f\u673a\u6620\u5c04 EXPOSE \u7684\u7aef\u53e3\u3002<\/li>\n<\/ul>\n<p>\u683c\u5f0f\uff1a<\/p>\n<p>EXPOSE &lt;\u7aef\u53e31&gt; [&lt;\u7aef\u53e32&gt;...]<\/p>\n<h5>WORKDIR<\/h5>\n<p>\u6307\u5b9a\u5de5\u4f5c\u76ee\u5f55\u3002\u7528 WORKDIR \u6307\u5b9a\u7684\u5de5\u4f5c\u76ee\u5f55\uff0c\u4f1a\u5728\u6784\u5efa\u955c\u50cf\u7684\u6bcf\u4e00\u5c42\u4e2d\u90fd\u5b58\u5728\u3002\uff08WORKDIR \u6307\u5b9a\u7684\u5de5\u4f5c\u76ee\u5f55\uff0c\u5fc5\u987b\u662f\u63d0\u524d\u521b\u5efa\u597d\u7684\uff09\u3002<\/p>\n<p>docker build \u6784\u5efa\u955c\u50cf\u8fc7\u7a0b\u4e2d\u7684\uff0c\u6bcf\u4e00\u4e2a RUN \u547d\u4ee4\u90fd\u662f\u65b0\u5efa\u7684\u4e00\u5c42\u3002\u53ea\u6709\u901a\u8fc7 WORKDIR \u521b\u5efa\u7684\u76ee\u5f55\u624d\u4f1a\u4e00\u76f4\u5b58\u5728\u3002<\/p>\n<p>\u683c\u5f0f\uff1a<\/p>\n<p>WORKDIR &lt;\u5de5\u4f5c\u76ee\u5f55\u8def\u5f84&gt;<\/p>\n<h5>USER<\/h5>\n<p>\u7528\u4e8e\u6307\u5b9a\u6267\u884c\u540e\u7eed\u547d\u4ee4\u7684\u7528\u6237\u548c\u7528\u6237\u7ec4\uff0c\u8fd9\u8fb9\u53ea\u662f\u5207\u6362\u540e\u7eed\u547d\u4ee4\u6267\u884c\u7684\u7528\u6237\uff08\u7528\u6237\u548c\u7528\u6237\u7ec4\u5fc5\u987b\u63d0\u524d\u5df2\u7ecf\u5b58\u5728\uff09\u3002<\/p>\n<p>\u683c\u5f0f\uff1a<\/p>\n<p>USER &lt;\u7528\u6237\u540d&gt;[:&lt;\u7528\u6237\u7ec4&gt;]<\/p>\n<h5>HEALTHCHECK<\/h5>\n<p>\u7528\u4e8e\u6307\u5b9a\u67d0\u4e2a\u7a0b\u5e8f\u6216\u8005\u6307\u4ee4\u6765\u76d1\u63a7 docker \u5bb9\u5668\u670d\u52a1\u7684\u8fd0\u884c\u72b6\u6001\u3002<\/p>\n<p>\u683c\u5f0f\uff1a<\/p>\n<p>HEALTHCHECK [\u9009\u9879] CMD &lt;\u547d\u4ee4&gt;\uff1a\u8bbe\u7f6e\u68c0\u67e5\u5bb9\u5668\u5065\u5eb7\u72b6\u51b5\u7684\u547d\u4ee4<br \/>\nHEALTHCHECK NONE\uff1a\u5982\u679c\u57fa\u7840\u955c\u50cf\u6709\u5065\u5eb7\u68c0\u67e5\u6307\u4ee4\uff0c\u4f7f\u7528\u8fd9\u884c\u53ef\u4ee5\u5c4f\u853d\u6389\u5176\u5065\u5eb7\u68c0\u67e5\u6307\u4ee4<\/p>\n<p>HEALTHCHECK [\u9009\u9879] CMD &lt;\u547d\u4ee4&gt; : \u8fd9\u8fb9 CMD \u540e\u9762\u8ddf\u968f\u7684\u547d\u4ee4\u4f7f\u7528\uff0c\u53ef\u4ee5\u53c2\u8003 CMD \u7684\u7528\u6cd5\u3002<\/p>\n<h5>ONBUILD<\/h5>\n<p>\u7528\u4e8e\u5ef6\u8fdf\u6784\u5efa\u547d\u4ee4\u7684\u6267\u884c\u3002\u7b80\u5355\u7684\u8bf4\uff0c\u5c31\u662f Dockerfile \u91cc\u7528 ONBUILD \u6307\u5b9a\u7684\u547d\u4ee4\uff0c\u5728\u672c\u6b21\u6784\u5efa\u955c\u50cf\u7684\u8fc7\u7a0b\u4e2d\u4e0d\u4f1a\u6267\u884c\uff08\u5047\u8bbe\u955c\u50cf\u4e3a test-build\uff09\u3002\u5f53\u6709\u65b0\u7684 Dockerfile \u4f7f\u7528\u4e86\u4e4b\u524d\u6784\u5efa\u7684\u955c\u50cf FROM test-build \uff0c\u8fd9\u65f6\u6267\u884c\u65b0\u955c\u50cf\u7684 Dockerfile \u6784\u5efa\u65f6\u5019\uff0c\u4f1a\u6267\u884c test-build \u7684 Dockerfile \u91cc\u7684 ONBUILD \u6307\u5b9a\u7684\u547d\u4ee4\u3002<\/p>\n<p>\u683c\u5f0f\uff1a<\/p>\n<p>ONBUILD &lt;\u5176\u5b83\u6307\u4ee4&gt;<\/p>\n<h5>LABEL<\/h5>\n<p>LABEL \u6307\u4ee4\u7528\u6765\u7ed9\u955c\u50cf\u6dfb\u52a0\u4e00\u4e9b\u5143\u6570\u636e\uff08metadata\uff09\uff0c\u4ee5\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\uff0c\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p>LABEL <key>=<value> <key>=<value> <key>=<value> ...<\/p>\n<p>\u6bd4\u5982\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0\u955c\u50cf\u7684\u4f5c\u8005\uff1a<\/p>\n<p>LABEL org.opencontainers.image.authors=&quot;runoob&quot;<\/p>\n<\/blockquote>\n<h2>Docker Compose<\/h2>\n<p><strong>Compose \u662f\u7528\u4e8e\u5b9a\u4e49\u548c\u8fd0\u884c\u591a\u5bb9\u5668 Docker \u5e94\u7528\u7a0b\u5e8f\u7684\u5de5\u5177\u3002<\/strong><\/p>\n<h3>Compose \u5b89\u88c5<\/h3>\n<p>\u4ee5\u4e0b\u4e24\u4e2a\u547d\u4ee4\u90fd\u53ef\u4ee5<\/p>\n<pre><code class=\"language-shell\">sudo curl -L &quot;https:\/\/github.com\/docker\/compose\/releases\/download\/v2.2.2\/docker-compose-$(uname -s)-$(uname -m)&quot; -o \/usr\/local\/bin\/docker-compose<\/code><\/pre>\n<pre><code class=\"language-shell\">curl -L https:\/\/get.daocloud.io\/docker\/compose\/releases\/download\/v2.4.1\/docker-compose-`uname -s`-`uname -m` &gt; \/usr\/local\/bin\/docker-compose<\/code><\/pre>\n<p>\u5c06\u53ef\u6267\u884c\u6743\u9650\u5e94\u7528\u4e8e\u4e8c\u8fdb\u5236\u6587\u4ef6\uff1asudo chmod +x \/usr\/local\/bin\/docker-compose<\/p>\n<p>\u521b\u5efa\u8f6f\u94fe\uff1asudo ln -s \/usr\/local\/bin\/docker-compose \/usr\/bin\/docker-compose<\/p>\n<p>\u6d4b\u8bd5\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1adocker-compose --version<br \/>\ncker-compose version 1.24.1, build 4667896b<\/p>\n<p><strong>\u6ce8\u610f\uff1a \u5bf9\u4e8e alpine\uff0c\u9700\u8981\u4ee5\u4e0b\u4f9d\u8d56\u5305\uff1a py-pip\uff0cpython-dev\uff0clibffi-dev\uff0copenssl-dev\uff0cgcc\uff0clibc-dev\uff0c\u548c make\u3002<\/strong><\/p>\n<h3>Compose\u4f7f\u7528<\/h3>\n<p>Compose \u4f7f\u7528\u7684\u4e09\u4e2a\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528 Dockerfile \u5b9a\u4e49\u5e94\u7528\u7a0b\u5e8f\u7684\u73af\u5883\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528 docker-compose.yml \u5b9a\u4e49\u6784\u6210\u5e94\u7528\u7a0b\u5e8f\u7684\u670d\u52a1\uff0c\u8fd9\u6837\u5b83\u4eec\u53ef\u4ee5\u5728\u9694\u79bb\u73af\u5883\u4e2d\u4e00\u8d77\u8fd0\u884c\u3002<\/p>\n<\/li>\n<li>\n<p>\u6700\u540e\uff0c\u6267\u884c docker-compose up \u547d\u4ee4\u6765\u542f\u52a8\u5e76\u8fd0\u884c\u6574\u4e2a\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/li>\n<\/ul>\n<p>docker-compose.yml\u6587\u4ef6\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-yml\"># yaml \u914d\u7f6e\u5b9e\u4f8b\nversion: &#039;3&#039;\nservices:\n  web:\n    build: .\n    ports:\n   - &quot;5000:5000&quot;\n    volumes:\n   - .:\/code\n    - logvolume01:\/var\/log\n    links:\n   - redis\n  redis:\n    image: redis\nvolumes:\n  logvolume01: {}<\/code><\/pre>\n<h4>\u4f7f\u7528\u793a\u4f8b<\/h4>\n<blockquote>\n<h3>1\u3001\u51c6\u5907<\/h3>\n<p>\u521b\u5efa\u4e00\u4e2a\u6d4b\u8bd5\u76ee\u5f55\uff1a<\/p>\n<p>$ mkdir composetest<br \/>\n$ cd composetest<\/p>\n<p>\u5728\u6d4b\u8bd5\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a app.py \u7684\u6587\u4ef6\uff0c\u5e76\u590d\u5236\u7c98\u8d34\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<h2>composetest\/app.py \u6587\u4ef6\u4ee3\u7801<\/h2>\n<p>import\u00a0time  <\/p>\n<p>import\u00a0redis<br \/>\nfrom\u00a0flask\u00a0import\u00a0Flask  <\/p>\n<p>app\u00a0=\u00a0Flask(<strong>name<\/strong>)<br \/>\ncache\u00a0=\u00a0redis.Redis(host='redis',\u00a0port=6379)  <\/p>\n<p>def\u00a0get_hit_count():<br \/>\n\u00a0 \u00a0 retries\u00a0=\u00a05<br \/>\n\u00a0 \u00a0\u00a0while\u00a0True:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0\u00a0try:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0return\u00a0cache.incr('hits')<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0\u00a0except\u00a0redis.exceptions.ConnectionError\u00a0as\u00a0exc:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0if\u00a0retries\u00a0==\u00a00:<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0raise\u00a0exc<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 retries -=\u00a01<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0time.sleep(0.5)  <\/p>\n<p>@app.route('\/')<br \/>\ndef\u00a0hello():<br \/>\n\u00a0 \u00a0 count\u00a0=\u00a0get_hit_count()<br \/>\n\u00a0 \u00a0\u00a0return\u00a0'Hello World! I have been seen {} times.\\n'.format(count)  <\/p>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0credis \u662f\u5e94\u7528\u7a0b\u5e8f\u7f51\u7edc\u4e0a\u7684 redis \u5bb9\u5668\u7684\u4e3b\u673a\u540d\uff0c\u8be5\u4e3b\u673a\u4f7f\u7528\u7684\u7aef\u53e3\u4e3a 6379\u3002<\/p>\n<p>\u5728 composetest \u76ee\u5f55\u4e2d\u521b\u5efa\u53e6\u4e00\u4e2a\u540d\u4e3a\u00a0requirements.txt\u00a0\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<p>flask<br \/>\nredis<\/p>\n<h3>2\u3001\u521b\u5efa Dockerfile \u6587\u4ef6<\/h3>\n<p>\u5728 composetest \u76ee\u5f55\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u00a0Dockerfile\u00a0\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<p>FROM python:3.7-alpine<br \/>\nWORKDIR \/code<br \/>\nENV FLASK_APP app.py<br \/>\nENV FLASK_RUN_HOST 0.0.0.0<br \/>\nRUN apk add --no-cache gcc musl-dev linux-headers<br \/>\nCOPY requirements.txt requirements.txt<br \/>\nRUN pip install -r requirements.txt<br \/>\nCOPY . .<br \/>\nCMD [&quot;flask&quot;, &quot;run&quot;]<\/p>\n<p><strong>Dockerfile \u5185\u5bb9\u89e3\u91ca\uff1a<\/strong><\/p>\n<ul>\n<li>\n<p><strong>FROM python:3.7-alpine<\/strong>: \u4ece Python 3.7 \u6620\u50cf\u5f00\u59cb\u6784\u5efa\u955c\u50cf\u3002<\/p>\n<\/li>\n<li>\n<p><strong>WORKDIR \/code<\/strong>: \u5c06\u5de5\u4f5c\u76ee\u5f55\u8bbe\u7f6e\u4e3a \/code\u3002<\/p>\n<\/li>\n<li>\n<p>ENV FLASK_APP app.py<br \/>\nENV FLASK_RUN_HOST 0.0.0.0<\/p>\n<p>\u8bbe\u7f6e flask \u547d\u4ee4\u4f7f\u7528\u7684\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/li>\n<li>\n<p><strong>RUN apk add --no-cache gcc musl-dev linux-headers<\/strong>: \u5b89\u88c5 gcc\uff0c\u4ee5\u4fbf\u8bf8\u5982 MarkupSafe \u548c SQLAlchemy \u4e4b\u7c7b\u7684 Python \u5305\u53ef\u4ee5\u7f16\u8bd1\u52a0\u901f\u3002<\/p>\n<\/li>\n<li>\n<p>COPY requirements.txt requirements.txt<br \/>\nRUN pip install -r requirements.txt<\/p>\n<p>\u590d\u5236 requirements.txt \u5e76\u5b89\u88c5 Python \u4f9d\u8d56\u9879\u3002<\/p>\n<\/li>\n<li>\n<p><strong>COPY . .<\/strong>: \u5c06 . \u9879\u76ee\u4e2d\u7684\u5f53\u524d\u76ee\u5f55\u590d\u5236\u5230 . \u955c\u50cf\u4e2d\u7684\u5de5\u4f5c\u76ee\u5f55\u3002<\/p>\n<\/li>\n<li>\n<p><strong>CMD [&quot;flask&quot;, &quot;run&quot;]<\/strong>: \u5bb9\u5668\u63d0\u4f9b\u9ed8\u8ba4\u7684\u6267\u884c\u547d\u4ee4\u4e3a\uff1aflask run\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>3\u3001\u521b\u5efa docker-compose.yml<\/h3>\n<p>\u5728\u6d4b\u8bd5\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a docker-compose.yml \u7684\u6587\u4ef6\uff0c\u7136\u540e\u7c98\u8d34\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<h2>docker-compose.yml \u914d\u7f6e\u6587\u4ef6<\/h2>\n<h1>yaml \u914d\u7f6e<\/h1>\n<p>version:\u00a0'3'<br \/>\nservices:\u00a0 web:\u00a0 \u00a0 build:\u00a0.\u00a0 \u00a0 ports:  <\/p>\n<p>-\u00a0&quot;5000:5000&quot;\u00a0 redis:\u00a0 \u00a0 image:\u00a0&quot;redis:alpine&quot;  <\/p>\n<p>\u8be5 Compose \u6587\u4ef6\u5b9a\u4e49\u4e86\u4e24\u4e2a\u670d\u52a1\uff1aweb \u548c redis\u3002<\/p>\n<ul>\n<li><strong>web<\/strong>\uff1a\u8be5 web \u670d\u52a1\u4f7f\u7528\u4ece Dockerfile \u5f53\u524d\u76ee\u5f55\u4e2d\u6784\u5efa\u7684\u955c\u50cf\u3002\u7136\u540e\uff0c\u5b83\u5c06\u5bb9\u5668\u548c\u4e3b\u673a\u7ed1\u5b9a\u5230\u66b4\u9732\u7684\u7aef\u53e3 5000\u3002\u6b64\u793a\u4f8b\u670d\u52a1\u4f7f\u7528 Flask Web \u670d\u52a1\u5668\u7684\u9ed8\u8ba4\u7aef\u53e3 5000 \u3002<\/li>\n<li><strong>redis<\/strong>\uff1a\u8be5 redis \u670d\u52a1\u4f7f\u7528 Docker Hub \u7684\u516c\u5171 Redis \u6620\u50cf\u3002<\/li>\n<\/ul>\n<h3>4\u3001\u4f7f\u7528 Compose \u547d\u4ee4\u6784\u5efa\u548c\u8fd0\u884c\u60a8\u7684\u5e94\u7528<\/h3>\n<p>\u5728\u6d4b\u8bd5\u76ee\u5f55\u4e2d\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n<p>docker-compose up<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u5728\u540e\u53f0\u6267\u884c\u8be5\u670d\u52a1\u53ef\u4ee5\u52a0\u4e0a\u00a0-d\u00a0\u53c2\u6570\uff1a<\/p>\n<p>docker-compose up -d<\/p>\n<hr \/>\n<h2>yml \u914d\u7f6e\u6307\u4ee4\u53c2\u8003<\/h2>\n<h3>version<\/h3>\n<p>\u6307\u5b9a\u672c yml \u4f9d\u4ece\u7684 compose \u54ea\u4e2a\u7248\u672c\u5236\u5b9a\u7684\u3002<\/p>\n<h3>build<\/h3>\n<p>\u6307\u5b9a\u4e3a\u6784\u5efa\u955c\u50cf\u4e0a\u4e0b\u6587\u8def\u5f84\uff1a<\/p>\n<p>\u4f8b\u5982 webapp \u670d\u52a1\uff0c\u6307\u5b9a\u4e3a\u4ece\u4e0a\u4e0b\u6587\u8def\u5f84 .\/dir\/Dockerfile \u6240\u6784\u5efa\u7684\u955c\u50cf\uff1a<\/p>\n<p>version: &quot;3.7&quot;<br \/>\nservices:<br \/>\nwebapp:<br \/>\nbuild: .\/dir<\/p>\n<p>\u6216\u8005\uff0c\u4f5c\u4e3a\u5177\u6709\u5728\u4e0a\u4e0b\u6587\u6307\u5b9a\u7684\u8def\u5f84\u7684\u5bf9\u8c61\uff0c\u4ee5\u53ca\u53ef\u9009\u7684 Dockerfile \u548c args\uff1a<\/p>\n<p>version: &quot;3.7&quot;<br \/>\nservices:<br \/>\nwebapp:<br \/>\nbuild:<br \/>\ncontext: .\/dir<br \/>\ndockerfile: Dockerfile-alternate<br \/>\nargs:<br \/>\nbuildno: 1<br \/>\nlabels:<\/p>\n<ul>\n<li>&quot;com.example.description=Accounting webapp&quot;<\/li>\n<li>&quot;com.example.department=Finance&quot;<\/li>\n<li>&quot;com.example.label-with-empty-value&quot;<br \/>\ntarget: prod<\/li>\n<\/ul>\n<ul>\n<li>context\uff1a\u4e0a\u4e0b\u6587\u8def\u5f84\u3002<\/li>\n<li>dockerfile\uff1a\u6307\u5b9a\u6784\u5efa\u955c\u50cf\u7684 Dockerfile \u6587\u4ef6\u540d\u3002<\/li>\n<li>args\uff1a\u6dfb\u52a0\u6784\u5efa\u53c2\u6570\uff0c\u8fd9\u662f\u53ea\u80fd\u5728\u6784\u5efa\u8fc7\u7a0b\u4e2d\u8bbf\u95ee\u7684\u73af\u5883\u53d8\u91cf\u3002<\/li>\n<li>labels\uff1a\u8bbe\u7f6e\u6784\u5efa\u955c\u50cf\u7684\u6807\u7b7e\u3002<\/li>\n<li>target\uff1a\u591a\u5c42\u6784\u5efa\uff0c\u53ef\u4ee5\u6307\u5b9a\u6784\u5efa\u54ea\u4e00\u5c42\u3002<\/li>\n<\/ul>\n<h3>cap_add\uff0ccap_drop<\/h3>\n<p>\u6dfb\u52a0\u6216\u5220\u9664\u5bb9\u5668\u62e5\u6709\u7684\u5bbf\u4e3b\u673a\u7684\u5185\u6838\u529f\u80fd\u3002<\/p>\n<p>cap_add:<\/p>\n<ul>\n<li>ALL # \u5f00\u542f\u5168\u90e8\u6743\u9650<\/li>\n<\/ul>\n<p>cap_drop:<\/p>\n<ul>\n<li>SYS_PTRACE # \u5173\u95ed ptrace\u6743\u9650<\/li>\n<\/ul>\n<h3>cgroup_parent<\/h3>\n<p>\u4e3a\u5bb9\u5668\u6307\u5b9a\u7236 cgroup \u7ec4\uff0c\u610f\u5473\u7740\u5c06\u7ee7\u627f\u8be5\u7ec4\u7684\u8d44\u6e90\u9650\u5236\u3002<\/p>\n<p>cgroup_parent: m-executor-abcd<\/p>\n<h3>command<\/h3>\n<p>\u8986\u76d6\u5bb9\u5668\u542f\u52a8\u7684\u9ed8\u8ba4\u547d\u4ee4\u3002<\/p>\n<p>command: [&quot;bundle&quot;, &quot;exec&quot;, &quot;thin&quot;, &quot;-p&quot;, &quot;3000&quot;]<\/p>\n<h3>container_name<\/h3>\n<p>\u6307\u5b9a\u81ea\u5b9a\u4e49\u5bb9\u5668\u540d\u79f0\uff0c\u800c\u4e0d\u662f\u751f\u6210\u7684\u9ed8\u8ba4\u540d\u79f0\u3002<\/p>\n<p>container_name: my-web-container<\/p>\n<h3>depends_on<\/h3>\n<p>\u8bbe\u7f6e\u4f9d\u8d56\u5173\u7cfb\u3002<\/p>\n<ul>\n<li>docker-compose up \uff1a\u4ee5\u4f9d\u8d56\u6027\u987a\u5e8f\u542f\u52a8\u670d\u52a1\u3002\u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff0c\u5148\u542f\u52a8 db \u548c redis \uff0c\u624d\u4f1a\u542f\u52a8 web\u3002<\/li>\n<li>docker-compose up SERVICE \uff1a\u81ea\u52a8\u5305\u542b SERVICE \u7684\u4f9d\u8d56\u9879\u3002\u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff0cdocker-compose up web \u8fd8\u5c06\u521b\u5efa\u5e76\u542f\u52a8 db \u548c redis\u3002<\/li>\n<li>docker-compose stop \uff1a\u6309\u4f9d\u8d56\u5173\u7cfb\u987a\u5e8f\u505c\u6b62\u670d\u52a1\u3002\u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff0cweb \u5728 db \u548c redis \u4e4b\u524d\u505c\u6b62\u3002<\/li>\n<\/ul>\n<p>version: &quot;3.7&quot;<br \/>\nservices:<br \/>\nweb:<br \/>\nbuild: .<br \/>\ndepends_on:<\/p>\n<ul>\n<li>db      - redis<br \/>\nredis:<br \/>\nimage: redis<br \/>\ndb:<br \/>\nimage: postgres<\/li>\n<\/ul>\n<p>\u6ce8\u610f\uff1aweb \u670d\u52a1\u4e0d\u4f1a\u7b49\u5f85 redis db \u5b8c\u5168\u542f\u52a8 \u4e4b\u540e\u624d\u542f\u52a8\u3002<\/p>\n<h3>deploy<\/h3>\n<p>\u6307\u5b9a\u4e0e\u670d\u52a1\u7684\u90e8\u7f72\u548c\u8fd0\u884c\u6709\u5173\u7684\u914d\u7f6e\u3002\u53ea\u5728 swarm \u6a21\u5f0f\u4e0b\u624d\u4f1a\u6709\u7528\u3002<\/p>\n<p>version: &quot;3.7&quot;<br \/>\nservices:<br \/>\nredis:<br \/>\nimage: redis:alpine<br \/>\ndeploy:<br \/>\nmode\uff1areplicated<br \/>\nreplicas: 6<br \/>\nendpoint_mode: dnsrr<br \/>\nlabels:         description: &quot;This redis service label&quot;<br \/>\nresources:<br \/>\nlimits:<br \/>\ncpus: '0.50'<br \/>\nmemory: 50M<br \/>\nreservations:<br \/>\ncpus: '0.25'<br \/>\nmemory: 20M<br \/>\nrestart_policy:<br \/>\ncondition: on-failure<br \/>\ndelay: 5s<br \/>\nmax_attempts: 3<br \/>\nwindow: 120s<\/p>\n<p>\u53ef\u4ee5\u9009\u53c2\u6570\uff1a<\/p>\n<p><strong>endpoint_mode<\/strong>\uff1a\u8bbf\u95ee\u96c6\u7fa4\u670d\u52a1\u7684\u65b9\u5f0f\u3002<\/p>\n<p>endpoint_mode: vip <\/p>\n<h1>Docker \u96c6\u7fa4\u670d\u52a1\u4e00\u4e2a\u5bf9\u5916\u7684\u865a\u62df ip\u3002\u6240\u6709\u7684\u8bf7\u6c42\u90fd\u4f1a\u901a\u8fc7\u8fd9\u4e2a\u865a\u62df ip \u5230\u8fbe\u96c6\u7fa4\u670d\u52a1\u5185\u90e8\u7684\u673a\u5668\u3002<\/h1>\n<p>endpoint_mode: dnsrr<\/p>\n<h1>DNS \u8f6e\u8be2\uff08DNSRR\uff09\u3002\u6240\u6709\u7684\u8bf7\u6c42\u4f1a\u81ea\u52a8\u8f6e\u8be2\u83b7\u53d6\u5230\u96c6\u7fa4 ip \u5217\u8868\u4e2d\u7684\u4e00\u4e2a ip \u5730\u5740\u3002<\/h1>\n<p><strong>labels<\/strong>\uff1a\u5728\u670d\u52a1\u4e0a\u8bbe\u7f6e\u6807\u7b7e\u3002\u53ef\u4ee5\u7528\u5bb9\u5668\u4e0a\u7684 labels\uff08\u8ddf deploy \u540c\u7ea7\u7684\u914d\u7f6e\uff09 \u8986\u76d6 deploy \u4e0b\u7684 labels\u3002<\/p>\n<p><strong>mode<\/strong>\uff1a\u6307\u5b9a\u670d\u52a1\u63d0\u4f9b\u7684\u6a21\u5f0f\u3002<\/p>\n<ul>\n<li>\n<p><strong>replicated<\/strong>\uff1a\u590d\u5236\u670d\u52a1\uff0c\u590d\u5236\u6307\u5b9a\u670d\u52a1\u5230\u96c6\u7fa4\u7684\u673a\u5668\u4e0a\u3002<\/p>\n<\/li>\n<li>\n<p><strong>global<\/strong>\uff1a\u5168\u5c40\u670d\u52a1\uff0c\u670d\u52a1\u5c06\u90e8\u7f72\u81f3\u96c6\u7fa4\u7684\u6bcf\u4e2a\u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>\u56fe\u89e3\uff1a\u4e0b\u56fe\u4e2d\u9ec4\u8272\u7684\u65b9\u5757\u662f replicated \u6a21\u5f0f\u7684\u8fd0\u884c\u60c5\u51b5\uff0c\u7070\u8272\u65b9\u5757\u662f global \u6a21\u5f0f\u7684\u8fd0\u884c\u60c5\u51b5\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/ahui.blog\/wp-content\/uploads\/2022\/08\/post-424-62fc9fbd588c6.png\" alt=\"\" \/><\/p>\n<\/li>\n<\/ul>\n<p><strong>replicas\uff1amode<\/strong>\u00a0\u4e3a replicated \u65f6\uff0c\u9700\u8981\u4f7f\u7528\u6b64\u53c2\u6570\u914d\u7f6e\u5177\u4f53\u8fd0\u884c\u7684\u8282\u70b9\u6570\u91cf\u3002<\/p>\n<p><strong>resources<\/strong>\uff1a\u914d\u7f6e\u670d\u52a1\u5668\u8d44\u6e90\u4f7f\u7528\u7684\u9650\u5236\uff0c\u4f8b\u5982\u4e0a\u4f8b\u5b50\uff0c\u914d\u7f6e redis \u96c6\u7fa4\u8fd0\u884c\u9700\u8981\u7684 cpu \u7684\u767e\u5206\u6bd4 \u548c \u5185\u5b58\u7684\u5360\u7528\u3002\u907f\u514d\u5360\u7528\u8d44\u6e90\u8fc7\u9ad8\u51fa\u73b0\u5f02\u5e38\u3002<\/p>\n<p><strong>restart_policy<\/strong>\uff1a\u914d\u7f6e\u5982\u4f55\u5728\u9000\u51fa\u5bb9\u5668\u65f6\u91cd\u65b0\u542f\u52a8\u5bb9\u5668\u3002<\/p>\n<ul>\n<li>condition\uff1a\u53ef\u9009 none\uff0con-failure \u6216\u8005 any\uff08\u9ed8\u8ba4\u503c\uff1aany\uff09\u3002<\/li>\n<li>delay\uff1a\u8bbe\u7f6e\u591a\u4e45\u4e4b\u540e\u91cd\u542f\uff08\u9ed8\u8ba4\u503c\uff1a0\uff09\u3002<\/li>\n<li>max_attempts\uff1a\u5c1d\u8bd5\u91cd\u65b0\u542f\u52a8\u5bb9\u5668\u7684\u6b21\u6570\uff0c\u8d85\u51fa\u6b21\u6570\uff0c\u5219\u4e0d\u518d\u5c1d\u8bd5\uff08\u9ed8\u8ba4\u503c\uff1a\u4e00\u76f4\u91cd\u8bd5\uff09\u3002<\/li>\n<li>window\uff1a\u8bbe\u7f6e\u5bb9\u5668\u91cd\u542f\u8d85\u65f6\u65f6\u95f4\uff08\u9ed8\u8ba4\u503c\uff1a0\uff09\u3002<\/li>\n<\/ul>\n<p><strong>rollback_config<\/strong>\uff1a\u914d\u7f6e\u5728\u66f4\u65b0\u5931\u8d25\u7684\u60c5\u51b5\u4e0b\u5e94\u5982\u4f55\u56de\u6eda\u670d\u52a1\u3002<\/p>\n<ul>\n<li>parallelism\uff1a\u4e00\u6b21\u8981\u56de\u6eda\u7684\u5bb9\u5668\u6570\u3002\u5982\u679c\u8bbe\u7f6e\u4e3a0\uff0c\u5219\u6240\u6709\u5bb9\u5668\u5c06\u540c\u65f6\u56de\u6eda\u3002<\/li>\n<li>delay\uff1a\u6bcf\u4e2a\u5bb9\u5668\u7ec4\u56de\u6eda\u4e4b\u95f4\u7b49\u5f85\u7684\u65f6\u95f4\uff08\u9ed8\u8ba4\u4e3a0s\uff09\u3002<\/li>\n<li>failure_action\uff1a\u5982\u679c\u56de\u6eda\u5931\u8d25\uff0c\u8be5\u600e\u4e48\u529e\u3002\u5176\u4e2d\u4e00\u4e2a continue \u6216\u8005 pause\uff08\u9ed8\u8ba4pause\uff09\u3002<\/li>\n<li>monitor\uff1a\u6bcf\u4e2a\u5bb9\u5668\u66f4\u65b0\u540e\uff0c\u6301\u7eed\u89c2\u5bdf\u662f\u5426\u5931\u8d25\u4e86\u7684\u65f6\u95f4 (ns|us|ms|s|m|h)\uff08\u9ed8\u8ba4\u4e3a0s\uff09\u3002<\/li>\n<li>max_failure_ratio\uff1a\u5728\u56de\u6eda\u671f\u95f4\u53ef\u4ee5\u5bb9\u5fcd\u7684\u6545\u969c\u7387\uff08\u9ed8\u8ba4\u4e3a0\uff09\u3002<\/li>\n<li>order\uff1a\u56de\u6eda\u671f\u95f4\u7684\u64cd\u4f5c\u987a\u5e8f\u3002\u5176\u4e2d\u4e00\u4e2a stop-first\uff08\u4e32\u884c\u56de\u6eda\uff09\uff0c\u6216\u8005 start-first\uff08\u5e76\u884c\u56de\u6eda\uff09\uff08\u9ed8\u8ba4 stop-first \uff09\u3002<\/li>\n<\/ul>\n<p><strong>update_config<\/strong>\uff1a\u914d\u7f6e\u5e94\u5982\u4f55\u66f4\u65b0\u670d\u52a1\uff0c\u5bf9\u4e8e\u914d\u7f6e\u6eda\u52a8\u66f4\u65b0\u5f88\u6709\u7528\u3002<\/p>\n<ul>\n<li>parallelism\uff1a\u4e00\u6b21\u66f4\u65b0\u7684\u5bb9\u5668\u6570\u3002<\/li>\n<li>delay\uff1a\u5728\u66f4\u65b0\u4e00\u7ec4\u5bb9\u5668\u4e4b\u95f4\u7b49\u5f85\u7684\u65f6\u95f4\u3002<\/li>\n<li>failure_action\uff1a\u5982\u679c\u66f4\u65b0\u5931\u8d25\uff0c\u8be5\u600e\u4e48\u529e\u3002\u5176\u4e2d\u4e00\u4e2a continue\uff0crollback \u6216\u8005pause \uff08\u9ed8\u8ba4\uff1apause\uff09\u3002<\/li>\n<li>monitor\uff1a\u6bcf\u4e2a\u5bb9\u5668\u66f4\u65b0\u540e\uff0c\u6301\u7eed\u89c2\u5bdf\u662f\u5426\u5931\u8d25\u4e86\u7684\u65f6\u95f4 (ns|us|ms|s|m|h)\uff08\u9ed8\u8ba4\u4e3a0s\uff09\u3002<\/li>\n<li>max_failure_ratio\uff1a\u5728\u66f4\u65b0\u8fc7\u7a0b\u4e2d\u53ef\u4ee5\u5bb9\u5fcd\u7684\u6545\u969c\u7387\u3002<\/li>\n<li>order\uff1a\u56de\u6eda\u671f\u95f4\u7684\u64cd\u4f5c\u987a\u5e8f\u3002\u5176\u4e2d\u4e00\u4e2a stop-first\uff08\u4e32\u884c\u56de\u6eda\uff09\uff0c\u6216\u8005 start-first\uff08\u5e76\u884c\u56de\u6eda\uff09\uff08\u9ed8\u8ba4stop-first\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u6ce8<\/strong>\uff1a\u4ec5\u652f\u6301 V3.4 \u53ca\u66f4\u9ad8\u7248\u672c\u3002<\/p>\n<h3>devices<\/h3>\n<p>\u6307\u5b9a\u8bbe\u5907\u6620\u5c04\u5217\u8868\u3002<\/p>\n<p>devices:<\/p>\n<ul>\n<li>&quot;\/dev\/ttyUSB0:\/dev\/ttyUSB0&quot;<\/li>\n<\/ul>\n<h3>dns<\/h3>\n<p>\u81ea\u5b9a\u4e49 DNS \u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u662f\u5355\u4e2a\u503c\u6216\u5217\u8868\u7684\u591a\u4e2a\u503c\u3002<\/p>\n<p>dns: 8.8.8.8<\/p>\n<p>dns:<\/p>\n<ul>\n<li>8.8.8.8<\/li>\n<li>9.9.9.9<\/li>\n<\/ul>\n<h3>dns_search<\/h3>\n<p>\u81ea\u5b9a\u4e49 DNS \u641c\u7d22\u57df\u3002\u53ef\u4ee5\u662f\u5355\u4e2a\u503c\u6216\u5217\u8868\u3002<\/p>\n<p>dns_search: example.com<br \/>\ndns_search:<\/p>\n<ul>\n<li>dc1.example.com  - dc2.example.com<\/li>\n<\/ul>\n<h3>entrypoint<\/h3>\n<p>\u8986\u76d6\u5bb9\u5668\u9ed8\u8ba4\u7684 entrypoint\u3002<\/p>\n<p>entrypoint: \/code\/entrypoint.sh<\/p>\n<p>\u4e5f\u53ef\u4ee5\u662f\u4ee5\u4e0b\u683c\u5f0f\uff1a<\/p>\n<p>entrypoint:<\/p>\n<ul>\n<li>php    - -d    - zend_extension=\/usr\/local\/lib\/php\/extensions\/no-debug-non-zts-20100525\/xdebug.so    - -d    - memory_limit=-1<\/li>\n<li>vendor\/bin\/phpunit<\/li>\n<\/ul>\n<h3>env_file<\/h3>\n<p>\u4ece\u6587\u4ef6\u6dfb\u52a0\u73af\u5883\u53d8\u91cf\u3002\u53ef\u4ee5\u662f\u5355\u4e2a\u503c\u6216\u5217\u8868\u7684\u591a\u4e2a\u503c\u3002<\/p>\n<p>env_file: .env<\/p>\n<p>\u4e5f\u53ef\u4ee5\u662f\u5217\u8868\u683c\u5f0f\uff1a<\/p>\n<p>env_file:<\/p>\n<ul>\n<li>.\/common.env  - .\/apps\/web.env  - \/opt\/secrets.env<\/li>\n<\/ul>\n<h3>environment<\/h3>\n<p>\u6dfb\u52a0\u73af\u5883\u53d8\u91cf\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u6216\u5b57\u5178\u3001\u4efb\u4f55\u5e03\u5c14\u503c\uff0c\u5e03\u5c14\u503c\u9700\u8981\u7528\u5f15\u53f7\u5f15\u8d77\u6765\uff0c\u4ee5\u786e\u4fdd YML \u89e3\u6790\u5668\u4e0d\u4f1a\u5c06\u5176\u8f6c\u6362\u4e3a True \u6216 False\u3002<\/p>\n<p>environment:<br \/>\nRACK_ENV: development<br \/>\nSHOW: 'true'<\/p>\n<h3>expose<\/h3>\n<p>\u66b4\u9732\u7aef\u53e3\uff0c\u4f46\u4e0d\u6620\u5c04\u5230\u5bbf\u4e3b\u673a\uff0c\u53ea\u88ab\u8fde\u63a5\u7684\u670d\u52a1\u8bbf\u95ee\u3002<\/p>\n<p>\u4ec5\u53ef\u4ee5\u6307\u5b9a\u5185\u90e8\u7aef\u53e3\u4e3a\u53c2\u6570\uff1a<\/p>\n<p>expose:<\/p>\n<ul>\n<li>&quot;3000&quot;<\/li>\n<li>&quot;8000&quot;<\/li>\n<\/ul>\n<h3>extra_hosts<\/h3>\n<p>\u6dfb\u52a0\u4e3b\u673a\u540d\u6620\u5c04\u3002\u7c7b\u4f3c docker client --add-host\u3002<\/p>\n<p>extra_hosts:<\/p>\n<ul>\n<li>&quot;somehost:162.242.195.82&quot;<\/li>\n<li>&quot;otherhost:50.31.209.229&quot;<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u4f1a\u5728\u6b64\u670d\u52a1\u7684\u5185\u90e8\u5bb9\u5668\u4e2d \/etc\/hosts \u521b\u5efa\u4e00\u4e2a\u5177\u6709 ip \u5730\u5740\u548c\u4e3b\u673a\u540d\u7684\u6620\u5c04\u5173\u7cfb\uff1a<\/p>\n<p>162.242.195.82  somehost<br \/>\n50.31.209.229   otherhost<\/p>\n<h3>healthcheck<\/h3>\n<p>\u7528\u4e8e\u68c0\u6d4b docker \u670d\u52a1\u662f\u5426\u5065\u5eb7\u8fd0\u884c\u3002<\/p>\n<p>healthcheck:<br \/>\ntest: [&quot;CMD&quot;, &quot;curl&quot;, &quot;-f&quot;, &quot;<a href=\"http:\/\/localhost\">http:\/\/localhost<\/a>&quot;] # \u8bbe\u7f6e\u68c0\u6d4b\u7a0b\u5e8f<br \/>\ninterval: 1m30s # \u8bbe\u7f6e\u68c0\u6d4b\u95f4\u9694<br \/>\ntimeout: 10s # \u8bbe\u7f6e\u68c0\u6d4b\u8d85\u65f6\u65f6\u95f4<br \/>\nretries: 3 # \u8bbe\u7f6e\u91cd\u8bd5\u6b21\u6570<br \/>\nstart_period: 40s # \u542f\u52a8\u540e\uff0c\u591a\u5c11\u79d2\u5f00\u59cb\u542f\u52a8\u68c0\u6d4b\u7a0b\u5e8f<\/p>\n<h3>image<\/h3>\n<p>\u6307\u5b9a\u5bb9\u5668\u8fd0\u884c\u7684\u955c\u50cf\u3002\u4ee5\u4e0b\u683c\u5f0f\u90fd\u53ef\u4ee5\uff1a<\/p>\n<p>image: redis<br \/>\nimage: ubuntu:14.04<br \/>\nimage: tutum\/influxdb<br \/>\nimage: example-registry.com:4000\/postgresql<br \/>\nimage: a4bc65fd # \u955c\u50cfid<\/p>\n<h3>logging<\/h3>\n<p>\u670d\u52a1\u7684\u65e5\u5fd7\u8bb0\u5f55\u914d\u7f6e\u3002<\/p>\n<p>driver\uff1a\u6307\u5b9a\u670d\u52a1\u5bb9\u5668\u7684\u65e5\u5fd7\u8bb0\u5f55\u9a71\u52a8\u7a0b\u5e8f\uff0c\u9ed8\u8ba4\u503c\u4e3ajson-file\u3002\u6709\u4ee5\u4e0b\u4e09\u4e2a\u9009\u9879<\/p>\n<p>driver: &quot;json-file&quot;<br \/>\ndriver: &quot;syslog&quot;<br \/>\ndriver: &quot;none&quot;<\/p>\n<p>\u4ec5\u5728 json-file \u9a71\u52a8\u7a0b\u5e8f\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u53c2\u6570\uff0c\u9650\u5236\u65e5\u5fd7\u5f97\u6570\u91cf\u548c\u5927\u5c0f\u3002<\/p>\n<p>logging:<br \/>\ndriver: json-file<br \/>\noptions:<br \/>\nmax-size: &quot;200k&quot; # \u5355\u4e2a\u6587\u4ef6\u5927\u5c0f\u4e3a200k<br \/>\nmax-file: &quot;10&quot; # \u6700\u591a10\u4e2a\u6587\u4ef6<\/p>\n<p>\u5f53\u8fbe\u5230\u6587\u4ef6\u9650\u5236\u4e0a\u9650\uff0c\u4f1a\u81ea\u52a8\u5220\u9664\u65e7\u5f97\u6587\u4ef6\u3002<\/p>\n<p>syslog \u9a71\u52a8\u7a0b\u5e8f\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528 syslog-address \u6307\u5b9a\u65e5\u5fd7\u63a5\u6536\u5730\u5740\u3002<\/p>\n<p>logging:<br \/>\ndriver: syslog<br \/>\noptions:<br \/>\nsyslog-address: &quot;tcp:\/\/192.168.0.42:123&quot;<\/p>\n<h3>network_mode<\/h3>\n<p>\u8bbe\u7f6e\u7f51\u7edc\u6a21\u5f0f\u3002<\/p>\n<p>network_mode: &quot;bridge&quot;<br \/>\nnetwork_mode: &quot;host&quot;<br \/>\nnetwork_mode: &quot;none&quot;<br \/>\nnetwork_mode: &quot;service:[service name]&quot;<br \/>\nnetwork_mode: &quot;container:[container name\/id]&quot;<\/p>\n<p>networks<\/p>\n<p>\u914d\u7f6e\u5bb9\u5668\u8fde\u63a5\u7684\u7f51\u7edc\uff0c\u5f15\u7528\u9876\u7ea7 networks \u4e0b\u7684\u6761\u76ee \u3002<\/p>\n<p>services:<br \/>\nsome-service:<br \/>\nnetworks:<br \/>\nsome-network:<br \/>\naliases:<\/p>\n<ul>\n<li>alias1<br \/>\nother-network:<br \/>\naliases:<\/li>\n<li>alias2<br \/>\nnetworks:<br \/>\nsome-network:<\/p>\n<h1>Use a custom driver<\/h1>\n<p>driver: custom-driver-1<br \/>\nother-network:<\/p>\n<h1>Use a custom driver which takes special options<\/h1>\n<p>driver: custom-driver-2<\/p>\n<\/li>\n<\/ul>\n<p><strong>aliases<\/strong>\u00a0\uff1a\u540c\u4e00\u7f51\u7edc\u4e0a\u7684\u5176\u4ed6\u5bb9\u5668\u53ef\u4ee5\u4f7f\u7528\u670d\u52a1\u540d\u79f0\u6216\u6b64\u522b\u540d\u6765\u8fde\u63a5\u5230\u5bf9\u5e94\u5bb9\u5668\u7684\u670d\u52a1\u3002<\/p>\n<h3>restart<\/h3>\n<ul>\n<li>no\uff1a\u662f\u9ed8\u8ba4\u7684\u91cd\u542f\u7b56\u7565\uff0c\u5728\u4efb\u4f55\u60c5\u51b5\u4e0b\u90fd\u4e0d\u4f1a\u91cd\u542f\u5bb9\u5668\u3002<\/li>\n<li>always\uff1a\u5bb9\u5668\u603b\u662f\u91cd\u65b0\u542f\u52a8\u3002<\/li>\n<li>on-failure\uff1a\u5728\u5bb9\u5668\u975e\u6b63\u5e38\u9000\u51fa\u65f6\uff08\u9000\u51fa\u72b6\u6001\u975e0\uff09\uff0c\u624d\u4f1a\u91cd\u542f\u5bb9\u5668\u3002<\/li>\n<li>unless-stopped\uff1a\u5728\u5bb9\u5668\u9000\u51fa\u65f6\u603b\u662f\u91cd\u542f\u5bb9\u5668\uff0c\u4f46\u662f\u4e0d\u8003\u8651\u5728Docker\u5b88\u62a4\u8fdb\u7a0b\u542f\u52a8\u65f6\u5c31\u5df2\u7ecf\u505c\u6b62\u4e86\u7684\u5bb9\u5668<\/li>\n<\/ul>\n<p>restart: &quot;no&quot;<br \/>\nrestart: always<br \/>\nrestart: on-failure<br \/>\nrestart: unless-stopped<\/p>\n<p>\u6ce8\uff1aswarm \u96c6\u7fa4\u6a21\u5f0f\uff0c\u8bf7\u6539\u7528 restart_policy\u3002<\/p>\n<h3>secrets<\/h3>\n<p>\u5b58\u50a8\u654f\u611f\u6570\u636e\uff0c\u4f8b\u5982\u5bc6\u7801\uff1a<\/p>\n<p>version: &quot;3.1&quot;<br \/>\nservices:<\/p>\n<p>mysql:<br \/>\nimage: mysql<br \/>\nenvironment:<br \/>\nMYSQL_ROOT_PASSWORD_FILE: \/run\/secrets\/my_secret<br \/>\nsecrets:<\/p>\n<ul>\n<li>my_secret<br \/>\nsecrets:<br \/>\nmy_secret:<br \/>\nfile: .\/my_secret.txt<\/li>\n<\/ul>\n<h3>security_opt<\/h3>\n<p>\u4fee\u6539\u5bb9\u5668\u9ed8\u8ba4\u7684 schema \u6807\u7b7e\u3002<\/p>\n<p>security-opt\uff1a<\/p>\n<ul>\n<li>label:user:USER   # \u8bbe\u7f6e\u5bb9\u5668\u7684\u7528\u6237\u6807\u7b7e<\/li>\n<li>label:role:ROLE   # \u8bbe\u7f6e\u5bb9\u5668\u7684\u89d2\u8272\u6807\u7b7e<\/li>\n<li>label:type:TYPE   # \u8bbe\u7f6e\u5bb9\u5668\u7684\u5b89\u5168\u7b56\u7565\u6807\u7b7e<\/li>\n<li>label:level:LEVEL  # \u8bbe\u7f6e\u5bb9\u5668\u7684\u5b89\u5168\u7b49\u7ea7\u6807\u7b7e<\/li>\n<\/ul>\n<h3>stop_grace_period<\/h3>\n<p>\u6307\u5b9a\u5728\u5bb9\u5668\u65e0\u6cd5\u5904\u7406 SIGTERM (\u6216\u8005\u4efb\u4f55 stop_signal \u7684\u4fe1\u53f7)\uff0c\u7b49\u5f85\u591a\u4e45\u540e\u53d1\u9001 SIGKILL \u4fe1\u53f7\u5173\u95ed\u5bb9\u5668\u3002<\/p>\n<p>stop_grace_period: 1s # \u7b49\u5f85 1 \u79d2<br \/>\nstop_grace_period: 1m30s # \u7b49\u5f85 1 \u5206 30 \u79d2 <\/p>\n<p>\u9ed8\u8ba4\u7684\u7b49\u5f85\u65f6\u95f4\u662f 10 \u79d2\u3002<\/p>\n<h3>stop_signal<\/h3>\n<p>\u8bbe\u7f6e\u505c\u6b62\u5bb9\u5668\u7684\u66ff\u4ee3\u4fe1\u53f7\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f7f\u7528 SIGTERM \u3002<\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\uff0c\u4f7f\u7528 SIGUSR1 \u66ff\u4ee3\u4fe1\u53f7 SIGTERM \u6765\u505c\u6b62\u5bb9\u5668\u3002<\/p>\n<p>stop_signal: SIGUSR1<\/p>\n<h3>sysctls<\/h3>\n<p>\u8bbe\u7f6e\u5bb9\u5668\u4e2d\u7684\u5185\u6838\u53c2\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u6216\u5b57\u5178\u683c\u5f0f\u3002<\/p>\n<p>sysctls:<br \/>\nnet.core.somaxconn: 1024<br \/>\nnet.ipv4.tcp_syncookies: 0<\/p>\n<p>sysctls:<\/p>\n<ul>\n<li>net.core.somaxconn=1024<\/li>\n<li>net.ipv4.tcp_syncookies=0<\/li>\n<\/ul>\n<h3>tmpfs<\/h3>\n<p>\u5728\u5bb9\u5668\u5185\u5b89\u88c5\u4e00\u4e2a\u4e34\u65f6\u6587\u4ef6\u7cfb\u7edf\u3002\u53ef\u4ee5\u662f\u5355\u4e2a\u503c\u6216\u5217\u8868\u7684\u591a\u4e2a\u503c\u3002<\/p>\n<p>tmpfs: \/run<br \/>\ntmpfs:<\/p>\n<ul>\n<li>\/run  - \/tmp<\/li>\n<\/ul>\n<h3>ulimits<\/h3>\n<p>\u8986\u76d6\u5bb9\u5668\u9ed8\u8ba4\u7684 ulimit\u3002<\/p>\n<p>ulimits:<br \/>\nnproc: 65535<br \/>\nnofile:<br \/>\nsoft: 20000<br \/>\nhard: 40000<\/p>\n<h3>volumes<\/h3>\n<p>\u5c06\u4e3b\u673a\u7684\u6570\u636e\u5377\u6216\u7740\u6587\u4ef6\u6302\u8f7d\u5230\u5bb9\u5668\u91cc\u3002<\/p>\n<p>version: &quot;3.7&quot;<br \/>\nservices:<br \/>\ndb:<br \/>\nimage: postgres:latest<br \/>\nvolumes:<\/p>\n<ul>\n<li>&quot;\/localhost\/postgres.sock:\/var\/run\/postgres\/postgres.sock&quot;<\/li>\n<li>&quot;\/localhost\/data:\/var\/lib\/postgresql\/data&quot;<\/li>\n<\/ul>\n<\/blockquote>\n<h2>Docker Machine<\/h2>\n<p>Docker Machine \u662f\u4e00\u79cd\u53ef\u4ee5\u8ba9\u60a8\u5728\u865a\u62df\u4e3b\u673a\u4e0a\u5b89\u88c5 Docker \u7684\u5de5\u5177\uff0c\u5e76\u53ef\u4ee5\u4f7f\u7528 docker-machine \u547d\u4ee4\u6765\u7ba1\u7406\u4e3b\u673a\u3002Docker Machine \u4e5f\u53ef\u4ee5\u96c6\u4e2d\u7ba1\u7406\u6240\u6709\u7684 docker \u4e3b\u673a\uff0c\u6bd4\u5982\u5feb\u901f\u7684\u7ed9 100 \u53f0\u670d\u52a1\u5668\u5b89\u88c5\u4e0a docker\u3002<\/p>\n<h3>\u5b89\u88c5<\/h3>\n<p>linux\uff1a<\/p>\n<pre><code class=\"language-shell\">base=https:\/\/github.com\/docker\/machine\/releases\/download\/v0.16.0 &amp;&amp;\n  curl -L $base\/docker-machine-$(uname -s)-$(uname -m) &gt;\/tmp\/docker-machine &amp;&amp;\n  sudo mv \/tmp\/docker-machine \/usr\/local\/bin\/docker-machine &amp;&amp;\n  chmod +x \/usr\/local\/bin\/docker-machine<\/code><\/pre>\n<p>macOS\uff1a<\/p>\n<pre><code class=\"language-shell\">base=https:\/\/github.com\/docker\/machine\/releases\/download\/v0.16.0 &amp;&amp;\n  curl -L $base\/docker-machine-$(uname -s)-$(uname -m) &gt;\/usr\/local\/bin\/docker-machine &amp;&amp;\n  chmod +x \/usr\/local\/bin\/docker-machine<\/code><\/pre>\n<p>windows:<\/p>\n<pre><code class=\"language-shell\">base=https:\/\/github.com\/docker\/machine\/releases\/download\/v0.16.0 &amp;&amp;\n  mkdir -p &quot;$HOME\/bin&quot; &amp;&amp;\n  curl -L $base\/docker-machine-Windows-x86_64.exe &gt; &quot;$HOME\/bin\/docker-machine.exe&quot; &amp;&amp;\n  chmod +x &quot;$HOME\/bin\/docker-machine.exe&quot;<\/code><\/pre>\n<p>\u67e5\u770b\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1adocker-machine version<\/p>\n<p>\u5217\u51fa\u53ef\u7528\u7684\u673a\u5668\uff1adocker-machine ls<\/p>\n<p>\u521b\u5efa\u673a\u5668\uff1adocker-machine create --driver virtualbox test<\/p>\n<ul>\n<li><strong>--driver<\/strong>\uff1a\u6307\u5b9a\u7528\u6765\u521b\u5efa\u673a\u5668\u7684\u9a71\u52a8\u7c7b\u578b\uff0c\u8fd9\u91cc\u662f virtualbox\u3002<\/li>\n<\/ul>\n<p>\u67e5\u770b\u673a\u5668IP\uff1adocker-machine ip test<\/p>\n<p>\u505c\u6b62\u673a\u5668\uff1adocker-machine stop test<\/p>\n<p>\u542f\u52a8\u673a\u5668\uff1adocker-machine start test<\/p>\n<p>\u8fdb\u5165\u673a\u5668\uff1adocker-machine ssh test<\/p>\n<p>\u67e5\u770b\u5f53\u524d\u6fc0\u6d3b\u72b6\u6001\u7684 Docker \u4e3b\u673a\uff1adocker-machine active<\/p>\n<ul>\n<li><strong>config<\/strong>\uff1a\u67e5\u770b\u5f53\u524d\u6fc0\u6d3b\u72b6\u6001 Docker \u4e3b\u673a\u7684\u8fde\u63a5\u4fe1\u606f\u3002<\/li>\n<li><strong>create<\/strong>\uff1a\u521b\u5efa Docker \u4e3b\u673a<\/li>\n<li><strong>env<\/strong>\uff1a\u663e\u793a\u8fde\u63a5\u5230\u67d0\u4e2a\u4e3b\u673a\u9700\u8981\u7684\u73af\u5883\u53d8\u91cf<\/li>\n<li><strong>inspect<\/strong>\uff1a \u4ee5 json \u683c\u5f0f\u8f93\u51fa\u6307\u5b9aDocker\u7684\u8be6\u7ec6\u4fe1\u606f<\/li>\n<li><strong>ip<\/strong>\uff1a \u83b7\u53d6\u6307\u5b9a Docker \u4e3b\u673a\u7684\u5730\u5740<\/li>\n<li><strong>kill<\/strong>\uff1a \u76f4\u63a5\u6740\u6b7b\u6307\u5b9a\u7684 Docker \u4e3b\u673a<\/li>\n<li><strong>ls<\/strong>\uff1a \u5217\u51fa\u6240\u6709\u7684\u7ba1\u7406\u4e3b\u673a<\/li>\n<li><strong>provision<\/strong>\uff1a \u91cd\u65b0\u914d\u7f6e\u6307\u5b9a\u4e3b\u673a<\/li>\n<li><strong>regenerate-certs<\/strong>\uff1a \u4e3a\u67d0\u4e2a\u4e3b\u673a\u91cd\u65b0\u751f\u6210 TLS \u4fe1\u606f<\/li>\n<li><strong>restart<\/strong>\uff1a \u91cd\u542f\u6307\u5b9a\u7684\u4e3b\u673a<\/li>\n<li><strong>rm<\/strong>\uff1a \u5220\u9664\u67d0\u53f0 Docker \u4e3b\u673a\uff0c\u5bf9\u5e94\u7684\u865a\u62df\u673a\u4e5f\u4f1a\u88ab\u5220\u9664<\/li>\n<li><strong>ssh<\/strong>\uff1a \u901a\u8fc7 SSH \u8fde\u63a5\u5230\u4e3b\u673a\u4e0a\uff0c\u6267\u884c\u547d\u4ee4<\/li>\n<li><strong>scp<\/strong>\uff1a \u5728 Docker \u4e3b\u673a\u4e4b\u95f4\u4ee5\u53ca Docker \u4e3b\u673a\u548c\u672c\u5730\u4e3b\u673a\u4e4b\u95f4\u901a\u8fc7 scp \u8fdc\u7a0b\u590d\u5236\u6570\u636e<\/li>\n<li><strong>mount<\/strong>\uff1a \u4f7f\u7528 SSHFS \u4ece\u8ba1\u7b97\u673a\u88c5\u8f7d\u6216\u5378\u8f7d\u76ee\u5f55<\/li>\n<li><strong>start<\/strong>\uff1a \u542f\u52a8\u4e00\u4e2a\u6307\u5b9a\u7684 Docker \u4e3b\u673a\uff0c\u5982\u679c\u5bf9\u8c61\u662f\u4e2a\u865a\u62df\u673a\uff0c\u8be5\u865a\u62df\u673a\u5c06\u88ab\u542f\u52a8<\/li>\n<li><strong>status<\/strong>\uff1a \u83b7\u53d6\u6307\u5b9a Docker \u4e3b\u673a\u7684\u72b6\u6001(\u5305\u62ec\uff1aRunning\u3001Paused\u3001Saved\u3001Stopped\u3001Stopping\u3001Starting\u3001Error)\u7b49<\/li>\n<li><strong>stop<\/strong>\uff1a \u505c\u6b62\u4e00\u4e2a\u6307\u5b9a\u7684 Docker \u4e3b\u673a<\/li>\n<li><strong>upgrade<\/strong>\uff1a \u5c06\u4e00\u4e2a\u6307\u5b9a\u4e3b\u673a\u7684 Docker \u7248\u672c\u66f4\u65b0\u4e3a\u6700\u65b0<\/li>\n<li><strong>url<\/strong>\uff1a \u83b7\u53d6\u6307\u5b9a Docker \u4e3b\u673a\u7684\u76d1\u542c URL<\/li>\n<li><strong>version<\/strong>\uff1a \u663e\u793a Docker Machine \u7684\u7248\u672c\u6216\u8005\u4e3b\u673a Docker \u7248\u672c<\/li>\n<li><strong>help<\/strong>\uff1a \u663e\u793a\u5e2e\u52a9\u4fe1\u606f<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00\uff1a\u590d\u4e60\u4e00\u4e0b\uff0c\u987a\u4fbf\u8bb0\u5f55\u4e00\u4e0b\uff0c\u65b9\u4fbf\u4ee5\u540e\u518d\u67e5\u4f7f\u7528\u65b9\u6cd5\u3002 Docker\u5b89\u88c5\u3001\u914d\u7f6e\u4ee5\u53ca\u66f4\u6362\u955c\u50cf\u6e90 docker\u5b89\u88c5\uff1a &#8230; <a title=\"Docker\u4f7f\u7528\u901f\u67e5\u624b\u518c\" class=\"read-more\" href=\"https:\/\/ahui.blog\/index.php\/2022\/08\/17\/docker_use\/\" aria-label=\"\u7ee7\u7eed\u9605\u8bfbDocker\u4f7f\u7528\u901f\u67e5\u624b\u518c\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[31],"class_list":["post-424","post","type-post","status-publish","format-standard","hentry","category-basic_knowledge","tag-docker"],"_links":{"self":[{"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/posts\/424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/comments?post=424"}],"version-history":[{"count":1,"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/posts\/424\/revisions"}],"predecessor-version":[{"id":426,"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/posts\/424\/revisions\/426"}],"wp:attachment":[{"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/media?parent=424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/categories?post=424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ahui.blog\/index.php\/wp-json\/wp\/v2\/tags?post=424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}