{"id":2908,"date":"2019-02-28T12:01:06","date_gmt":"2019-02-28T04:01:06","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=2908"},"modified":"2019-02-28T12:01:06","modified_gmt":"2019-02-28T04:01:06","slug":"docker%e5%91%bd%e4%bb%a4%e8%af%a6%e8%a7%a3%ef%bc%88run%e7%af%87%ef%bc%89","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/2908","title":{"rendered":"Docker\u547d\u4ee4\u8be6\u89e3\uff08run\u7bc7\uff09"},"content":{"rendered":"<div class=\"postBody\">\n<div id=\"cnblogs_post_body\" class=\"blogpost-body cnblogs-markdown\">\n<p>\u547d\u4ee4\u683c\u5f0f\uff1a<code>docker run [OPTIONS] IMAGE [COMMAND] [ARG...]<\/code><br \/>\nUsage: Run a command in a new container<br \/>\n\u4e2d\u6587\u610f\u601d\u4e3a\uff1a\u901a\u8fc7run\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5bb9\u5668\uff08container\uff09<\/p>\n<ul>\n<li>\u5e38\u7528\u9009\u9879\u8bf4\u660e\n<ul>\n<li><code>-d, --detach=false<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u8fd0\u884c\u4e8e\u524d\u53f0\u8fd8\u662f\u540e\u53f0\uff0c\u9ed8\u8ba4\u4e3afalse<\/li>\n<li><code>-i, --interactive=false<\/code>\uff0c \u6253\u5f00STDIN\uff0c\u7528\u4e8e\u63a7\u5236\u53f0\u4ea4\u4e92<\/li>\n<li><code>-t, --tty=false<\/code>\uff0c \u5206\u914dtty\u8bbe\u5907\uff0c\u8be5\u53ef\u4ee5\u652f\u6301\u7ec8\u7aef\u767b\u5f55\uff0c\u9ed8\u8ba4\u4e3afalse<\/li>\n<li><code>-u, --user=\"\"<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u7684\u7528\u6237<\/li>\n<li><code>-a, --attach=[]<\/code>\uff0c \u767b\u5f55\u5bb9\u5668\uff08\u5fc5\u987b\u662f\u4ee5docker run -d\u542f\u52a8\u7684\u5bb9\u5668\uff09<\/li>\n<li><code>-w, --workdir=\"\"<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u7684\u5de5\u4f5c\u76ee\u5f55<\/li>\n<li><code>-c, --cpu-shares=0<\/code>\uff0c \u8bbe\u7f6e\u5bb9\u5668CPU\u6743\u91cd\uff0c\u5728CPU\u5171\u4eab\u573a\u666f\u4f7f\u7528<\/li>\n<li><code>-e, --env=[]<\/code>\uff0c \u6307\u5b9a\u73af\u5883\u53d8\u91cf\uff0c\u5bb9\u5668\u4e2d\u53ef\u4ee5\u4f7f\u7528\u8be5\u73af\u5883\u53d8\u91cf<\/li>\n<li><code>-m, --memory=\"\"<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u7684\u5185\u5b58\u4e0a\u9650<\/li>\n<li><code>-P, --publish-all=false<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u66b4\u9732\u7684\u7aef\u53e3<\/li>\n<li><code>-p, --publish=[]<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u66b4\u9732\u7684\u7aef\u53e3<\/li>\n<li><code>-h, --hostname=\"\"<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u7684\u4e3b\u673a\u540d<\/li>\n<li><code>-v, --volume=[]<\/code>\uff0c \u7ed9\u5bb9\u5668\u6302\u8f7d\u5b58\u50a8\u5377\uff0c\u6302\u8f7d\u5230\u5bb9\u5668\u7684\u67d0\u4e2a\u76ee\u5f55<\/li>\n<li><code>--volumes-from=[]<\/code>\uff0c \u7ed9\u5bb9\u5668\u6302\u8f7d\u5176\u4ed6\u5bb9\u5668\u4e0a\u7684\u5377\uff0c\u6302\u8f7d\u5230\u5bb9\u5668\u7684\u67d0\u4e2a\u76ee\u5f55<\/li>\n<li><code>--cap-add=[]<\/code>\uff0c \u6dfb\u52a0\u6743\u9650\uff0c\u6743\u9650\u6e05\u5355\u8be6\u89c1\uff1a<a class=\"uri\" href=\"http:\/\/linux.die.net\/man\/7\/capabilities\">http:\/\/linux.die.net\/man\/7\/capabilities<\/a><\/li>\n<li><code>--cap-drop=[]<\/code>\uff0c \u5220\u9664\u6743\u9650\uff0c\u6743\u9650\u6e05\u5355\u8be6\u89c1\uff1a<a class=\"uri\" href=\"http:\/\/linux.die.net\/man\/7\/capabilities\">http:\/\/linux.die.net\/man\/7\/capabilities<\/a><\/li>\n<li><code>--cidfile=\"\"<\/code>\uff0c \u8fd0\u884c\u5bb9\u5668\u540e\uff0c\u5728\u6307\u5b9a\u6587\u4ef6\u4e2d\u5199\u5165\u5bb9\u5668PID\u503c\uff0c\u4e00\u79cd\u5178\u578b\u7684\u76d1\u63a7\u7cfb\u7edf\u7528\u6cd5<\/li>\n<li><code>--cpuset=\"\"<\/code>\uff0c \u8bbe\u7f6e\u5bb9\u5668\u53ef\u4ee5\u4f7f\u7528\u54ea\u4e9bCPU\uff0c\u6b64\u53c2\u6570\u53ef\u4ee5\u7528\u6765\u5bb9\u5668\u72ec\u5360CPU<\/li>\n<li><code>--device=[]<\/code>\uff0c \u6dfb\u52a0\u4e3b\u673a\u8bbe\u5907\u7ed9\u5bb9\u5668\uff0c\u76f8\u5f53\u4e8e\u8bbe\u5907\u76f4\u901a<\/li>\n<li><code>--dns=[]<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u7684dns\u670d\u52a1\u5668<\/li>\n<li><code>--dns-search=[]<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u7684dns\u641c\u7d22\u57df\u540d\uff0c\u5199\u5165\u5230\u5bb9\u5668\u7684\/etc\/resolv.conf\u6587\u4ef6<\/li>\n<li><code>--entrypoint=\"\"<\/code>\uff0c \u8986\u76d6image\u7684\u5165\u53e3\u70b9<\/li>\n<li><code>--env-file=[]<\/code>\uff0c \u6307\u5b9a\u73af\u5883\u53d8\u91cf\u6587\u4ef6\uff0c\u6587\u4ef6\u683c\u5f0f\u4e3a\u6bcf\u884c\u4e00\u4e2a\u73af\u5883\u53d8\u91cf<\/li>\n<li><code>--expose=[]<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u66b4\u9732\u7684\u7aef\u53e3\uff0c\u5373\u4fee\u6539\u955c\u50cf\u7684\u66b4\u9732\u7aef\u53e3<\/li>\n<li><code>--link=[]<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u95f4\u7684\u5173\u8054\uff0c\u4f7f\u7528\u5176\u4ed6\u5bb9\u5668\u7684IP\u3001env\u7b49\u4fe1\u606f<\/li>\n<li><code>--lxc-conf=[]<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u53ea\u6709\u5728\u6307\u5b9a&#8211;exec-driver=lxc\u65f6\u4f7f\u7528<\/li>\n<li><code>--name=\"\"<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u540d\u5b57\uff0c\u540e\u7eed\u53ef\u4ee5\u901a\u8fc7\u540d\u5b57\u8fdb\u884c\u5bb9\u5668\u7ba1\u7406\uff0clinks\u7279\u6027\u9700\u8981\u4f7f\u7528\u540d\u5b57<\/li>\n<li><code>--net=\"bridge\"<\/code>\uff0c \u5bb9\u5668\u7f51\u7edc\u8bbe\u7f6e:\n<ul>\n<li>bridge \u4f7f\u7528docker daemon\u6307\u5b9a\u7684\u7f51\u6865<\/li>\n<li>host \/\/\u5bb9\u5668\u4f7f\u7528\u4e3b\u673a\u7684\u7f51\u7edc<\/li>\n<li>container:NAME_or_ID &gt;\/\/\u4f7f\u7528\u5176\u4ed6\u5bb9\u5668\u7684\u7f51\u8def\uff0c\u5171\u4eabIP\u548cPORT\u7b49\u7f51\u7edc\u8d44\u6e90<\/li>\n<li>none \u5bb9\u5668\u4f7f\u7528\u81ea\u5df1\u7684\u7f51\u7edc\uff08\u7c7b\u4f3c&#8211;net=bridge\uff09\uff0c\u4f46\u662f\u4e0d\u8fdb\u884c\u914d\u7f6e<\/li>\n<\/ul>\n<\/li>\n<li><code>--privileged=false<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u662f\u5426\u4e3a\u7279\u6743\u5bb9\u5668\uff0c\u7279\u6743\u5bb9\u5668\u62e5\u6709\u6240\u6709\u7684capabilities<\/li>\n<li><code>--restart=\"no\"<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u505c\u6b62\u540e\u7684\u91cd\u542f\u7b56\u7565:\n<ul>\n<li>no\uff1a\u5bb9\u5668\u9000\u51fa\u65f6\u4e0d\u91cd\u542f<\/li>\n<li>on-failure\uff1a\u5bb9\u5668\u6545\u969c\u9000\u51fa\uff08\u8fd4\u56de\u503c\u975e\u96f6\uff09\u65f6\u91cd\u542f<\/li>\n<li>always\uff1a\u5bb9\u5668\u9000\u51fa\u65f6\u603b\u662f\u91cd\u542f<\/li>\n<\/ul>\n<\/li>\n<li><code>--rm=false<\/code>\uff0c \u6307\u5b9a\u5bb9\u5668\u505c\u6b62\u540e\u81ea\u52a8\u5220\u9664\u5bb9\u5668(\u4e0d\u652f\u6301\u4ee5docker run -d\u542f\u52a8\u7684\u5bb9\u5668)<\/li>\n<li><code>--sig-proxy=true<\/code>\uff0c \u8bbe\u7f6e\u7531\u4ee3\u7406\u63a5\u53d7\u5e76\u5904\u7406\u4fe1\u53f7\uff0c\u4f46\u662fSIGCHLD\u3001SIGSTOP\u548cSIGKILL\u4e0d\u80fd\u88ab\u4ee3\u7406<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h1 id=\"\u793a\u4f8b\">\u793a\u4f8b<\/h1>\n<ul>\n<li>\u8fd0\u884c\u4e00\u4e2a\u5728\u540e\u53f0\u6267\u884c\u7684\u5bb9\u5668\uff0c\u540c\u65f6\uff0c\u8fd8\u80fd\u7528\u63a7\u5236\u53f0\u7ba1\u7406\uff1a<code>docker run -i -t -d ubuntu:latest<\/code><\/li>\n<li>\u8fd0\u884c\u4e00\u4e2a\u5e26\u547d\u4ee4\u5728\u540e\u53f0\u4e0d\u65ad\u6267\u884c\u7684\u5bb9\u5668\uff0c\u4e0d\u76f4\u63a5\u5c55\u793a\u5bb9\u5668\u5185\u90e8\u4fe1\u606f\uff1a<code>docker run -d ubuntu:latest ping www.docker.com<\/code><\/li>\n<li>\u8fd0\u884c\u4e00\u4e2a\u5728\u540e\u53f0\u4e0d\u65ad\u6267\u884c\u7684\u5bb9\u5668\uff0c\u540c\u65f6\u5e26\u6709\u547d\u4ee4\uff0c\u7a0b\u5e8f\u88ab\u7ec8\u6b62\u540e\u8fd8\u80fd\u91cd\u542f\u7ee7\u7eed\u8dd1\uff0c\u8fd8\u80fd\u7528\u63a7\u5236\u53f0\u7ba1\u7406\uff0c<code>docker run -d --restart=always ubuntu:latest ping www.docker.com<\/code><\/li>\n<li>\u4e3a\u5bb9\u5668\u6307\u5b9a\u4e00\u4e2a\u540d\u5b57\uff0c<code>docker run -d --name=ubuntu_server ubuntu:latest<\/code><\/li>\n<li>\u5bb9\u5668\u66b4\u973280\u7aef\u53e3\uff0c\u5e76\u6307\u5b9a\u5bbf\u4e3b\u673a80\u7aef\u53e3\u4e0e\u5176\u901a\u4fe1(<strong>:<\/strong>\u00a0\u4e4b\u524d\u662f\u5bbf\u4e3b\u673a\u7aef\u53e3\uff0c\u4e4b\u540e\u662f\u5bb9\u5668\u9700\u66b4\u9732\u7684\u7aef\u53e3)\uff0c<code>docker run -d --name=ubuntu_server -p 80:80 ubuntu:latest<\/code><\/li>\n<li>\u6307\u5b9a\u5bb9\u5668\u5185\u76ee\u5f55\u4e0e\u5bbf\u4e3b\u673a\u76ee\u5f55\u5171\u4eab(<strong>:<\/strong>\u00a0\u4e4b\u524d\u662f\u5bbf\u4e3b\u673a\u6587\u4ef6\u5939\uff0c\u4e4b\u540e\u662f\u5bb9\u5668\u9700\u5171\u4eab\u7684\u6587\u4ef6\u5939)\uff0c<code>docker run -d --name=ubuntu_server -v \/etc\/www:\/var\/www ubuntu:latest<\/code><\/li>\n<\/ul>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u547d\u4ee4\u683c\u5f0f\uff1adocker run [OPT<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[122],"class_list":["post-2908","post","type-post","status-publish","format-standard","hentry","tag-06-godocker"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/2908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=2908"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/2908\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=2908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=2908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=2908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}