
{"id":4666,"date":"2020-03-20T21:12:59","date_gmt":"2020-03-21T01:12:59","guid":{"rendered":"https:\/\/ikriv.com\/blog\/?p=4666"},"modified":"2020-03-20T21:12:59","modified_gmt":"2020-03-21T01:12:59","slug":"how-to-prevent-docker-container-from-exiting","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=4666","title":{"rendered":"How to prevent docker container from exiting"},"content":{"rendered":"<p>A docker containing not running anything particular in the foreground will exit immediately after start.<\/p>\n<p>Specifying <code>\/bin\/sh<\/code> as the startup command does not help. Some Internet sources suggest <code>tail -f \/dev\/null<\/code>, and it works, but such container cannot be stopped gracefully. The best solution I could find was a shell script running a wait loop:<\/p>\n<pre>\r\n<font color=\"darkgreen\"># Dockerfile<\/font>\r\n<b>FROM<\/b> alpine\r\n<b>CMD<\/b> while true; do sleep 1000; done\r\n<\/pre>\n<p>This takes a few seconds to stop gracefully, but it does go down eventually.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A docker containing not running anything particular in the foreground will exit immediately after start. Specifying \/bin\/sh as the startup command does not help. Some Internet sources suggest tail -f <a href=\"https:\/\/ikriv.com\/blog\/?p=4666\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[4],"tags":[],"class_list":["entry","author-ikriv","post-4666","post","type-post","status-publish","format-standard","category-hack"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4666"}],"version-history":[{"count":2,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4666\/revisions"}],"predecessor-version":[{"id":4668,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4666\/revisions\/4668"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}