{"id":291125,"date":"2021-07-05T14:00:56","date_gmt":"2021-07-05T11:00:56","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-keep-docker-containers-running-when-the-daemon-stops-cloudsavvy-it\/"},"modified":"2021-07-05T14:00:56","modified_gmt":"2021-07-05T11:00:56","slug":"how-to-keep-docker-containers-running-when-the-daemon-stops-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-keep-docker-containers-running-when-the-daemon-stops-cloudsavvy-it\/","title":{"rendered":"#How to Keep Docker Containers Running When the Daemon Stops \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a351b396a2cc\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a351b396a2cc\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-keep-docker-containers-running-when-the-daemon-stops-cloudsavvy-it\/#Why_Does_This_Matter\" >Why Does This Matter?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-keep-docker-containers-running-when-the-daemon-stops-cloudsavvy-it\/#Container_Live_Restore\" >Container Live Restore<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-keep-docker-containers-running-when-the-daemon-stops-cloudsavvy-it\/#Handling_Sustained_Daemon-less_Running\" >Handling Sustained Daemon-less Running<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-keep-docker-containers-running-when-the-daemon-stops-cloudsavvy-it\/#Live_Restore_Caveats\" >Live Restore Caveats<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-keep-docker-containers-running-when-the-daemon-stops-cloudsavvy-it\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Keep Docker Containers Running When the Daemon Stops \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage aligncenter size-full wp-image-10864\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/04\/075c8694.jpeg?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Illustration showing the Docker logo\" width=\"1600\" height=\"900\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>When Docker terminates, all your containers are stopped. The default installation doesn\u2019t let containers run unless the daemon is also up. Here\u2019s how to minimize workload downtime by keeping containers alive during a daemon outage.<\/p>\n<h2 id=\"why-does-this-matter\"><span class=\"ez-toc-section\" id=\"Why_Does_This_Matter\"><\/span>Why Does This Matter?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker has proven to be a reliable system that\u2019s capable of supporting solutions in production. That\u2019s not to say it\u2019s infallible. You could still encounter a crash that knocks the daemon out of action, taking your containers offline.<\/p>\n<p>In another scenario, your operating system\u2019s package manager might auto-update Docker, causing a daemon restart and a brief period of downtime. Ideally, these situations could be resolved without any impact on your workloads. As the daemon only <em>manages<\/em> containers, implementing commands like <code>docker run<\/code> and <code>docker rm<\/code>, there\u2019s no inherent need for it to stick around through the intervening period in a container\u2019s lifecycle.<\/p>\n<h2 id=\"container-live-restore\"><span class=\"ez-toc-section\" id=\"Container_Live_Restore\"><\/span>Container Live Restore<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker supports a system called <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/config\/containers\/live-restore\">\u201clive restore\u201d<\/a> which makes this possible. Instead of terminating containers during daemon shutdown, Docker will keep them running. It\u2019ll pick up where it left off once restarted.<\/p>\n<p>Live restore must be manually enabled. You can use it on a one-off basis by running <code>dockerd<\/code> with the <code>--live-restore flag<\/code>:<\/p>\n<pre>sudo dockerd --live-restore<\/pre>\n<p>To permanently enable live restore, add it to your Docker daemon configuration file. This is usually found at <code>\/etc\/docker\/daemon.json<\/code>. You\u2019ll need to create the file if it doesn\u2019t already exist.<\/p>\n<p>Next you need to instruct Docker to reload its configuration. A reload will not impact your containers, unlike a full daemon restart.<\/p>\n<pre>sudo systemctl reload docker<\/pre>\n<p>Live restore should now be activated. You can test it out by stopping the Docker daemon.<\/p>\n<pre>sudo systemctl stop docker<\/pre>\n<p>Any running containers should stay active, even though the daemon is shutdown. You won\u2019t be able to use <code>docker<\/code> commands, as the daemon connection will be gone, but the containers will keep running and will retain their network connections.<\/p>\n<p>Docker will automatically detect the existing containers when it restarts. You\u2019ll be able to continue where you left off, without having to suffer any downtime.<\/p>\n<h2 id=\"handling-sustained-daemon-less-running\"><span class=\"ez-toc-section\" id=\"Handling_Sustained_Daemon-less_Running\"><\/span>Handling Sustained Daemon-less Running<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Running containers without an active daemon connection shouldn\u2019t have any serious consequences, even over a sustained time period. However, you will find logs start to get lost during a prolonged daemon outage.<\/p>\n<p>Docker containers pipe their logs into a first-in first-out (FIFO) buffer. The Docker daemon reads the buffer contents to create the persisted log files you view with <code>docker logs<\/code>.<\/p>\n<p>The default buffer size <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/config\/containers\/live-restore\/#impact-of-live-restore-on-running-containers\">is only 64K<\/a> so it can be exhausted if the daemon\u2019s not actively reading its contents. When the buffer fills, no more logs can be handled until the daemon completes a buffer flush. You can increase the buffer size by editing the value of <code>\/proc\/sys\/fs\/pipe-max-size<\/code>.<\/p>\n<h2 id=\"caveats-of-live-restore\"><span class=\"ez-toc-section\" id=\"Live_Restore_Caveats\"><\/span>Live Restore Caveats<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Live Restore should cover most scenarios where the Docker daemon shuts down and later recovers. This includes Docker updates but only between minor patch releases. If you install a new major Docker version (such as <code>19.03<\/code> to <code>20.10<\/code>), Live Restore won\u2019t be used and the Docker daemon will always be restarted.<\/p>\n<p>You should be wary of using Live Restore as a way to edit Docker daemon settings on the fly. Changing some options, such as bridge IP addresses, will prevent containers from restoring properly when the daemon restarts. If this h<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>ens, you\u2019ll need to manually stop all the affected containers and replace them with new ones. This situation could also arise if your operating system assigns a different networking setup after a reboot.<\/p>\n<p>Live Restore is intended for use during Docker updates and unplanned daemon outages. If you need to edit daemon settings, try to plan for downtime instead. You can also use <code>systemctl reload docker<\/code> to reload configuration files without completely restarting the daemon.<\/p>\n<p>There\u2019s not yet Live Restore for Windows-based containers. You <em>can<\/em> use Live Restore <em>on<\/em> Windows with Linux-based containers. It\u2019s built-in to Docker Desktop and is <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/config\/containers\/live-restore\/#impact-of-live-restore-on-running-containers\">enabled via<\/a> Preferences &gt; Daemon &gt; Advanced.<\/p>\n<h2 id=\"conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Live Restore lets you minimize disruptive downtime by keeping containers running in the absence of the Docker daemon. If you need to install an urgent Docker update, or you hit a surprise crash, your workloads should stay operational while the daemon restarts.<\/p>\n<p>Activating Live Restore is a best practice step when running Docker in production. Configuration analysis tools may flag installations which don\u2019t have it enabled.<\/p>\n<p>Beyond using Live Restore, you should ensure your containers have got appropriate restart policies too. Using <code>restart: always<\/code> will make individual containers come back up after an OS restart, or any other daemon launch where Live Restore couldn\u2019t be used.\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/12361\/how-to-keep-docker-containers-running-when-the-daemon-stops\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Keep Docker Containers Running When the Daemon Stops \u2013 CloudSavvy IT&#8221; When Docker terminates, all your containers are stopped. The default installation doesn\u2019t let containers run unless the daemon is also up. Here\u2019s how to minimize workload downtime by keeping containers alive during a daemon outage. Why Does This Matter? Docker has proven&#8230;<\/p>\n","protected":false},"author":1,"featured_media":291126,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/04\/075c8694.jpeg","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-291125","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/291125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=291125"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/291125\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/291126"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=291125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=291125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=291125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}