{"id":41,"date":"2019-05-13T13:57:32","date_gmt":"2019-05-13T05:57:32","guid":{"rendered":"https:\/\/thereisno.top:4430\/?p=41"},"modified":"2019-05-13T13:57:32","modified_gmt":"2019-05-13T05:57:32","slug":"docker-%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/thereisno.top\/?p=41","title":{"rendered":"Docker \u5e38\u7528\u547d\u4ee4"},"content":{"rendered":"\n<p><strong>1. \u67e5\u770bdocker\u4fe1\u606f\uff08version\u3001info\uff09<\/strong><\/p>\n\n\n\n<p># \u67e5\u770bdocker\u7248\u672c<br>\n$docker version<\/p>\n\n\n\n<p># \u663e\u793adocker\u7cfb\u7edf\u7684\u4fe1\u606f<br>\n$docker <strong>info<\/strong><\/p>\n\n\n\n<p><strong>2. \u5bf9image\u7684\u64cd\u4f5c\uff08search\u3001pull\u3001images\u3001rmi\u3001history\uff09<\/strong><\/p>\n\n\n\n<p># \u68c0\u7d22image<br>\n$docker search image_name<\/p>\n\n\n\n<p># \u4e0b\u8f7dimage<br>\n$docker pull image_name<\/p>\n\n\n\n<p># \u5217\u51fa\u955c\u50cf\u5217\u8868; -a, &#8211;all=false\nShow all images; &#8211;no-trunc=false Don&#8217;t truncate output; -q, &#8211;quiet=false Only\nshow numeric IDs<br>\n$docker images<\/p>\n\n\n\n<p># \u5220\u9664\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u955c\u50cf; -f,\n&#8211;force=false Force; &#8211;no-prune=false Do not delete untagged parents<br>\n$docker rmi image_name<\/p>\n\n\n\n<p># \u663e\u793a\u4e00\u4e2a\u955c\u50cf\u7684\u5386\u53f2;\n&#8211;no-trunc=false Don&#8217;t truncate output; -q, &#8211;quiet=false Only show numeric IDs<br>\n$docker history image_name<\/p>\n\n\n\n<p><strong>3.&nbsp;\u542f\u52a8\u5bb9\u5668\uff08run\uff09<\/strong><\/p>\n\n\n\n<p>docker\u5bb9\u5668\u53ef\u4ee5\u7406\u89e3\u4e3a\u5728\u6c99\u76d2\u4e2d\u8fd0\u884c\u7684\u8fdb\u7a0b\u3002\u8fd9\u4e2a\u6c99\u76d2\u5305\u542b\u4e86\u8be5\u8fdb\u7a0b\u8fd0\u884c\u6240\u5fc5\u987b\u7684\u8d44\u6e90\uff0c\u5305\u62ec\u6587\u4ef6\u7cfb\u7edf\u3001\u7cfb\u7edf\u7c7b\u5e93\u3001shell\n\u73af\u5883\u7b49\u7b49\u3002\u4f46\u8fd9\u4e2a\u6c99\u76d2\u9ed8\u8ba4\u662f\u4e0d\u4f1a\u8fd0\u884c\u4efb\u4f55\u7a0b\u5e8f\u7684\u3002\u4f60\u9700\u8981\u5728\u6c99\u76d2\u4e2d\u8fd0\u884c\u4e00\u4e2a\u8fdb\u7a0b\u6765\u542f\u52a8\u67d0\u4e00\u4e2a\u5bb9\u5668\u3002\u8fd9\u4e2a\u8fdb\u7a0b\u662f\u8be5\u5bb9\u5668\u7684\u552f\u4e00\u8fdb\u7a0b\uff0c\u6240\u4ee5\u5f53\u8be5\u8fdb\u7a0b\u7ed3\u675f\u7684\u65f6\u5019\uff0c\u5bb9\u5668\u4e5f\u4f1a\u5b8c\u5168\u7684\u505c\u6b62\u3002<\/p>\n\n\n\n<p>#\n\u5728\u5bb9\u5668\u4e2d\u8fd0\u884c&#8221;echo&#8221;\u547d\u4ee4\uff0c\u8f93\u51fa&#8221;hello word&#8221;<br>\n$docker <strong>run<\/strong> image_name echo &#8220;hello\nword&#8221;<\/p>\n\n\n\n<p># \u4ea4\u4e92\u5f0f\u8fdb\u5165\u5bb9\u5668\u4e2d<br>\n$docker <strong>run<\/strong>\n-i -t image_name \/bin\/bash<\/p>\n\n\n\n<p># \u5728\u5bb9\u5668\u4e2d\u5b89\u88c5\u65b0\u7684\u7a0b\u5e8f<br>\n$docker <strong>run<\/strong>\nimage_name apt-get install -y app_name<\/p>\n\n\n\n<p>Note\uff1a\n&nbsp;\u5728\u6267\u884capt-get\n\u547d\u4ee4\u7684\u65f6\u5019\uff0c\u8981\u5e26\u4e0a-y\u53c2\u6570\u3002\u5982\u679c\u4e0d\u6307\u5b9a-y\u53c2\u6570\u7684\u8bdd\uff0capt-get\u547d\u4ee4\u4f1a\u8fdb\u5165\u4ea4\u4e92\u6a21\u5f0f\uff0c\u9700\u8981\u7528\u6237\u8f93\u5165\u547d\u4ee4\u6765\u8fdb\u884c\u786e\u8ba4\uff0c\u4f46\u5728docker\u73af\u5883\u4e2d\u662f\u65e0\u6cd5\u54cd\u5e94\u8fd9\u79cd\u4ea4\u4e92\u7684\u3002apt-get\n\u547d\u4ee4\u6267\u884c\u5b8c\u6bd5\u4e4b\u540e\uff0c\u5bb9\u5668\u5c31\u4f1a\u505c\u6b62\uff0c\u4f46\u5bf9\u5bb9\u5668\u7684\u6539\u52a8\u4e0d\u4f1a\u4e22\u5931\u3002<\/p>\n\n\n\n<p><strong>4. \u67e5\u770b\u5bb9\u5668\uff08ps\uff09<\/strong><\/p>\n\n\n\n<p># \u5217\u51fa\u5f53\u524d\u6240\u6709\u6b63\u5728\u8fd0\u884c\u7684container<br>\n$docker ps<br>\n# \u5217\u51fa\u6240\u6709\u7684container<br>\n$docker ps -a<br>\n# \u5217\u51fa\u6700\u8fd1\u4e00\u6b21\u542f\u52a8\u7684container<br>\n$docker ps -l<\/p>\n\n\n\n<p><strong>5. \u4fdd\u5b58\u5bf9\u5bb9\u5668\u7684\u4fee\u6539\uff08commit\uff09<\/strong><\/p>\n\n\n\n<p>\u5f53\u4f60\u5bf9\u67d0\u4e00\u4e2a\u5bb9\u5668\u505a\u4e86\u4fee\u6539\u4e4b\u540e\uff08\u901a\u8fc7\u5728\u5bb9\u5668\u4e2d\u8fd0\u884c\u67d0\u4e00\u4e2a\u547d\u4ee4\uff09\uff0c\u53ef\u4ee5\u628a\u5bf9\u5bb9\u5668\u7684\u4fee\u6539\u4fdd\u5b58\u4e0b\u6765\uff0c\u8fd9\u6837\u4e0b\u6b21\u53ef\u4ee5\u4ece\u4fdd\u5b58\u540e\u7684\u6700\u65b0\u72b6\u6001\u8fd0\u884c\u8be5\u5bb9\u5668\u3002<\/p>\n\n\n\n<p># \u4fdd\u5b58\u5bf9\u5bb9\u5668\u7684\u4fee\u6539; -a, &#8211;author=&#8221;&#8221;\nAuthor; -m, &#8211;message=&#8221;&#8221; Commit message<br>\n$docker commit ID new_image_name<\/p>\n\n\n\n<p>Note\uff1a&nbsp;&nbsp;image\u76f8\u5f53\u4e8e\u7c7b\uff0ccontainer\u76f8\u5f53\u4e8e\u5b9e\u4f8b\uff0c\u4e0d\u8fc7\u53ef\u4ee5\u52a8\u6001\u7ed9\u5b9e\u4f8b\u5b89\u88c5\u65b0\u8f6f\u4ef6\uff0c\u7136\u540e\u628a\u8fd9\u4e2acontainer\u7528commit\u547d\u4ee4\u56fa\u5316\u6210\u4e00\u4e2aimage\u3002<\/p>\n\n\n\n<p><strong>6.\n\u5bf9\u5bb9\u5668\u7684\u64cd\u4f5c\uff08rm\u3001stop\u3001start\u3001kill\u3001logs\u3001diff\u3001top\u3001cp\u3001restart\u3001attach\uff09<\/strong><\/p>\n\n\n\n<p># \u5220\u9664\u6240\u6709\u5bb9\u5668<br>\n$docker rm `docker ps -a -q`<\/p>\n\n\n\n<p># \u5220\u9664\u5355\u4e2a\u5bb9\u5668; -f,\n&#8211;force=false; -l, &#8211;link=false Remove the specified link and not the\nunderlying container; -v, &#8211;volumes=false Remove the volumes associated to the\ncontainer<br>\n$docker rm Name\/ID<\/p>\n\n\n\n<p># \u505c\u6b62\u3001\u542f\u52a8\u3001\u6740\u6b7b\u4e00\u4e2a\u5bb9\u5668<br>\n$docker stop Name\/ID<br>\n$docker start Name\/ID<br>\n$docker kill Name\/ID<\/p>\n\n\n\n<p># \u4ece\u4e00\u4e2a\u5bb9\u5668\u4e2d\u53d6\u65e5\u5fd7; -f,\n&#8211;follow=false Follow log output; -t, &#8211;timestamps=false Show timestamps<br>\n$docker logs Name\/ID<\/p>\n\n\n\n<p>#\n\u5217\u51fa\u4e00\u4e2a\u5bb9\u5668\u91cc\u9762\u88ab\u6539\u53d8\u7684\u6587\u4ef6\u6216\u8005\u76ee\u5f55\uff0clist\u5217\u8868\u4f1a\u663e\u793a\u51fa\u4e09\u79cd\u4e8b\u4ef6\uff0cA \u589e\u52a0\u7684\uff0cD \u5220\u9664\u7684\uff0cC \u88ab\u6539\u53d8\u7684<br>\n$docker diff Name\/ID<\/p>\n\n\n\n<p># \u663e\u793a\u4e00\u4e2a\u8fd0\u884c\u7684\u5bb9\u5668\u91cc\u9762\u7684\u8fdb\u7a0b\u4fe1\u606f<br>\n$docker top Name\/ID<\/p>\n\n\n\n<p># \u4ece\u5bb9\u5668\u91cc\u9762\u62f7\u8d1d\u6587\u4ef6\/\u76ee\u5f55\u5230\u672c\u5730\u4e00\u4e2a\u8def\u5f84<br>\n$docker cp Name:\/container_path\nto_path<br>\n$docker cp ID:\/container_path\nto_path<\/p>\n\n\n\n<p># \u91cd\u542f\u4e00\u4e2a\u6b63\u5728\u8fd0\u884c\u7684\u5bb9\u5668; -t,\n&#8211;time=10 Number of seconds to try to stop for before killing the container,\nDefault=10<br>\n$docker restart Name\/ID<\/p>\n\n\n\n<p># \u9644\u52a0\u5230\u4e00\u4e2a\u8fd0\u884c\u7684\u5bb9\u5668\u4e0a\u9762;\n&#8211;no-stdin=false Do not attach stdin; &#8211;sig-proxy=true Proxify all received\nsignal to the process<br>\n$docker attach ID<\/p>\n\n\n\n<p>Note\uff1a&nbsp;attach\u547d\u4ee4\u5141\u8bb8\u4f60\u67e5\u770b\u6216\u8005\u5f71\u54cd\u4e00\u4e2a\u8fd0\u884c\u7684\u5bb9\u5668\u3002\u4f60\u53ef\u4ee5\u5728\u540c\u4e00\u65f6\u95f4attach\u540c\u4e00\u4e2a\u5bb9\u5668\u3002\u4f60\u4e5f\u53ef\u4ee5\u4ece\u4e00\u4e2a\u5bb9\u5668\u4e2d\u8131\u79bb\u51fa\u6765\uff0c\u662f\u4eceCTRL-C\u3002<\/p>\n\n\n\n<p><strong>7. \u4fdd\u5b58\u548c\u52a0\u8f7d\u955c\u50cf\uff08save\u3001load\uff09<\/strong><\/p>\n\n\n\n<p>\u5f53\u9700\u8981\u628a\u4e00\u53f0\u673a\u5668\u4e0a\u7684\u955c\u50cf\u8fc1\u79fb\u5230\u53e6\u4e00\u53f0\u673a\u5668\u7684\u65f6\u5019\uff0c\u9700\u8981\u4fdd\u5b58\u955c\u50cf\u4e0e\u52a0\u8f7d\u955c\u50cf\u3002<\/p>\n\n\n\n<p># \u4fdd\u5b58\u955c\u50cf\u5230\u4e00\u4e2atar\u5305; -o,\n&#8211;output=&#8221;&#8221; Write to an file<br>\n$docker save image_name -o file_path<br>\n# \u52a0\u8f7d\u4e00\u4e2atar\u5305\u683c\u5f0f\u7684\u955c\u50cf; -i,\n&#8211;input=&#8221;&#8221; Read from a tar archive file<br>\n$docker load -i file_path<\/p>\n\n\n\n<p># \u673a\u5668a<br>\n$docker save image_name &gt; \/home\/save.tar<br>\n#\n\u4f7f\u7528scp\u5c06save.tar\u62f7\u5230\u673a\u5668b\u4e0a\uff0c\u7136\u540e\uff1a<br>\n$docker load &lt; \/home\/save.tar<\/p>\n\n\n\n<p><strong>8\u3001 \u767b\u5f55registry server\uff08login\uff09<\/strong><\/p>\n\n\n\n<p># \u767b\u9646registry server; -e, &#8211;email=&#8221;&#8221;\nEmail; -p, &#8211;password=&#8221;&#8221; Password; -u, &#8211;username=&#8221;&#8221; Username<br>\n$docker login<\/p>\n\n\n\n<p><strong>9. \u53d1\u5e03image\uff08push\uff09<\/strong><\/p>\n\n\n\n<p># \u53d1\u5e03docker\u955c\u50cf<br>\n$docker <strong>push<\/strong> new_image_name<\/p>\n\n\n\n<p><strong>10.&nbsp;&nbsp;\u6839\u636eDockerfile \u6784\u5efa\u51fa\u4e00\u4e2a\u5bb9\u5668<\/strong><\/p>\n\n\n\n<p>#build<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211;no-cache=false <strong>Do<\/strong> <strong>not<\/strong> use cache <strong>when<\/strong> building the image<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -q, &#8211;quiet=false Suppress the verbose output generated <strong>by<\/strong> the containers<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8211;rm=true Remove intermediate containers after a successful build<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -t, &#8211;tag=&#8221;&#8221; Repository name (<strong>and<\/strong> optionally a tag) <strong>to<\/strong> be applied <strong>to<\/strong> the resulting image <strong>in<\/strong> <strong>case<\/strong> <strong>of<\/strong>\nsuccess<br>\n$docker build -t image_name Dockerfile_path<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u67e5\u770bdocker\u4fe1\u606f\uff08version\u3001info\uff09 # \u67e5\u770bdocker\u7248\u672c $docker versio &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/thereisno.top\/?p=41\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cDocker \u5e38\u7528\u547d\u4ee4\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-41","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=41"}],"version-history":[{"count":1,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":42,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/41\/revisions\/42"}],"wp:attachment":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}