{"id":2997,"date":"2019-03-28T19:25:14","date_gmt":"2019-03-28T11:25:14","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=2997"},"modified":"2019-03-28T19:25:14","modified_gmt":"2019-03-28T11:25:14","slug":"docker-container%e5%bc%80%e6%9c%ba%e8%87%aa%e5%8a%a8%e5%90%af%e5%8a%a8","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/2997","title":{"rendered":"Docker Container\u5f00\u673a\u81ea\u52a8\u542f\u52a8"},"content":{"rendered":"<div class=\"clear\">\u91cd\u542f\u7b56\u7565\uff1a<\/div>\n<div class=\"postBody\">\n<div id=\"cnblogs_post_body\" class=\"blogpost-body\">\n<p>\u4f7f\u7528\u5728Docker run\u7684\u65f6\u5019\u4f7f\u7528&#8211;restart\u53c2\u6570\u6765\u8bbe\u7f6e\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">no - container\u4e0d\u91cd\u542f\r\non-failure - container\u63a8\u51fa\u72b6\u6001\u975e0\u65f6\u91cd\u542f\r\nalways - \u59cb\u7ec8\u91cd\u542f<\/pre>\n<p>https:\/\/docs.docker.com\/reference\/commandline\/cli\/#restart-policies<\/p>\n<h4 id=\"restart-policies\">Restart Policies<\/h4>\n<p>Using the\u00a0<code>--restart<\/code>\u00a0flag on Docker run you can specify a restart policy for how a container should or should not be restarted on exit.<\/p>\n<p><strong>no\u00a0<\/strong>&#8211; Do not restart the container when it exits.<\/p>\n<p><strong>on-failure\u00a0<\/strong>&#8211; Restart the container only if it exits with a non zero exit status.<\/p>\n<p><strong>always\u00a0<\/strong>&#8211; Always restart the container regardless of the exit status.<\/p>\n<p>You can also specify the maximum amount of times Docker will try to restart the container when using the<strong>on-failure\u00a0<\/strong>policy. The default is that Docker will try forever to restart the container.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">$ sudo docker run --restart=always redis<\/pre>\n<p>This will run the\u00a0<code>redis<\/code>\u00a0container with a restart policy of\u00a0<strong>always\u00a0<\/strong>so that if the container exits, Docker will restart it.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">$ sudo docker run --restart=on-failure:10 redis<\/pre>\n<p>This will run the\u00a0<code>redis<\/code>\u00a0container with a restart policy of\u00a0<strong>on-failure\u00a0<\/strong>and a maximum restart count of 10. If the\u00a0<code>redis<\/code>\u00a0container exits with a non-zero exit status more than 10 times in a row Docker will abort trying to restart the container. Providing a maximum restart limit is only valid for the\u00a0<strong>on-failure\u00a0<\/strong>policy.<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u91cd\u542f\u7b56\u7565\uff1a \u4f7f\u7528\u5728Docker run\u7684<\/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-2997","post","type-post","status-publish","format-standard","hentry","tag-06-godocker"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/2997","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=2997"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/2997\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=2997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=2997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=2997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}