{"id":330113,"date":"2021-08-25T15:00:01","date_gmt":"2021-08-25T12:00:01","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-check-if-the-docker-daemon-or-a-container-is-running-cloudsavvy-it\/"},"modified":"2021-08-25T15:00:01","modified_gmt":"2021-08-25T12:00:01","slug":"how-to-check-if-the-docker-daemon-or-a-container-is-running-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-check-if-the-docker-daemon-or-a-container-is-running-cloudsavvy-it\/","title":{"rendered":"#How to Check If the Docker Daemon or a Container Is Running \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 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-6a26baf9e4001\" 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-6a26baf9e4001\" 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-check-if-the-docker-daemon-or-a-container-is-running-cloudsavvy-it\/#Checking_With_Systemctl\" >Checking With Systemctl<\/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-check-if-the-docker-daemon-or-a-container-is-running-cloudsavvy-it\/#Inspecting_Process_Details\" >Inspecting Process Details<\/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-check-if-the-docker-daemon-or-a-container-is-running-cloudsavvy-it\/#Handling_Stuck_Process_Files\" >Handling Stuck Process Files<\/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-check-if-the-docker-daemon-or-a-container-is-running-cloudsavvy-it\/#Checking_Individual_Containers\" >Checking Individual Containers<\/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-check-if-the-docker-daemon-or-a-container-is-running-cloudsavvy-it\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Check If the Docker Daemon or a Container Is Running \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\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/04\/075c8694.jpeg?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/04\/075c8694.jpeg?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" 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\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Docker uses a daemon-based architecture where the CLI connects to a long-lived process running separately on your machine or a remote host. CLI commands won\u2019t work and your containers will usually go offline if the daemon stops.<\/p>\n<p>Here\u2019s how to check whether Docker\u2019s daemon is up so you can diagnose issues with containers and the <code>docker<\/code> command. When the daemon\u2019s not running, you\u2019ll see a \u201ccan\u2019t connect to Docker daemon\u201d message each time you use the <code>docker<\/code> CLI.<\/p>\n<h2 id=\"checking-with-systemctl\"><span class=\"ez-toc-section\" id=\"Checking_With_Systemctl\"><\/span>Checking With Systemctl<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can check Docker\u2019s status with <code>systemctl<\/code> on distributions that use Systemd for service management. This covers the majority of popular operating systems including Debian, Ubuntu, CentOS, and Red Hat.<\/p>\n<pre>sudo systemctl status docker<\/pre>\n<p>Check what\u2019s displayed under \u201cActive.\u201d If you see <code>active (running)<\/code> in green, the Docker daemon is running and your containers should be up.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13957\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/08\/e1e87514.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1175\" height=\"259\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>An active state of <code>inactive<\/code> indicates the service has stopped. Try to bring it up by running <code>sudo systemctl start docker<\/code>. The status should change to <code>active (running)<\/code> after the daemon starts.<\/p>\n<p>If you see a status of <code>failed<\/code> in red, the daemon couldn\u2019t start due to an error. You should review the service\u2019s startup logs shown later in the <code>systemctl<\/code> command output as these usually contain hints that let you work out what went wrong.<\/p>\n<p>When there\u2019s no obvious resolution available, manually start the daemon in debugging mode to get more information on its startup routine.<\/p>\n<pre>sudo dockerd --debug<\/pre>\n<p>Rebooting your host machine or restarting the Docker service with <code>systemctl restart docker<\/code> can help alleviate transient issues too.<\/p>\n<h2 id=\"inspecting-process-details\"><span class=\"ez-toc-section\" id=\"Inspecting_Process_Details\"><\/span>Inspecting Process Details<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Another way to check for a running Docker daemon is by inspecting its process ID file. The daemon writes its process ID to <code>\/var\/run\/docker.pid<\/code> each time it starts up. When this file exists, Docker should be running and ready for CLI connections.<\/p>\n<pre>cat \/var\/run\/docker.pid<\/pre>\n<p>You can use this technique to create programmatic <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\">script<\/a>s that check whether the daemon\u2019s alive. Reading the file gives you the ID which you can use with <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.howtogeek.com\/668986\/how-to-use-the-linux-top-command-and-understand-its-output\">tools like <code>top<\/code><\/a> to get more information about the Docker process:<\/p>\n<pre>cat \/var\/run\/docker.pid&#13;\n&#13;\n# process id = 1000&#13;\n&#13;\ntop -p 1000<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13958\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/08\/e7e7a87d.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1081\" height=\"247\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can also get the process ID with the<code>pidof<\/code>command. This accepts a process name and returns the first matching ID:<\/p>\n<pre>pidof dockerd&#13;\n&#13;\n# process id = 1000&#13;\n&#13;\n# view information with top&#13;\ntop -p `pidof dockerd`<\/pre>\n<p>There\u2019s an active Docker daemon on your machine if <code>top<\/code> matches a <code>dockerd<\/code> process. This can be more reliable than looking for <code>docker.pid<\/code> \u2013 if the daemon crashes, <code>docker.pid<\/code> could get left behind after the process is gone.<\/p>\n<h2 id=\"handling-stuck-process-files\"><span class=\"ez-toc-section\" id=\"Handling_Stuck_Process_Files\"><\/span>Handling Stuck Process Files<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The daemon will refuse to restart when a PID file is present. This could get you stuck in a restart loop if the file\u2019s actually orphaned from a previous run. You\u2019ll see this message when running <code>dockerd<\/code>:<\/p>\n<pre>failed to start daemon: pid file found, ensure docker is not running or delete \/var\/run\/docker.pid<\/pre>\n<p>Use <code>pidof dockerd<\/code> to make sure Docker\u2019s actually stopped. Proceed if the command emits no output, confirming there\u2019s no running process.<\/p>\n<p>Run <code>sudo rm \/var\/run\/docker.pid<\/code> to delete the old process ID file. The daemon should now start successfully next time you run <code>dockerd<\/code>or <code>service docker start<\/code>.<\/p>\n<p>PID file issues are commonly encountered when you snapshot a virtual machine and then create a new instance from the image. The process file will be included in the snapshot, causing the Docker daemon in the new VM to think it\u2019s already running.<\/p>\n<h2 id=\"checking-individual-containers\"><span class=\"ez-toc-section\" id=\"Checking_Individual_Containers\"><\/span>Checking Individual Containers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The status of individual containers is accessed via the <code>docker ps<\/code> command. This emits a table containing the details of all currently running containers.<\/p>\n<pre>docker ps<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13959\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/08\/21179279.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1136\" height=\"353\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Combine the <code>docker ps<\/code> command with <code>grep<\/code> to easily check whether a specific container is running by ID or name:<\/p>\n<pre>docker ps | grep my-container-name<\/pre>\n<p>Now the output will be filtered to show the container you\u2019ve selected. There\u2019ll be no records if the container isn\u2019t running.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13961\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/08\/81901725.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"967\" height=\"150\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Stopped containers are displayed using <code>docker ps -a<\/code>. A stopped container can be started with the <code>docker start<\/code> command:<\/p>\n<pre>docker start my-container<\/pre>\n<p>The container will then move into the regular <code>docker ps<\/code> output. You can stop it again with <code>docker stop my-container<\/code>.<\/p>\n<h2 id=\"conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You\u2019ve got several options to consider when you want to know whether Docker is running. There\u2019s your operating system\u2019s service manager, the <code>docker.pid<\/code> file, and regular process inspection tools such as <code>top<\/code> and <code>pidof<\/code>.<\/p>\n<p>When it comes to individual containers, <code>docker ps<\/code> provides the list of everything that\u2019s currently running on your host. More comprehensive information on the state of any container can be gleaned with <code>docker inspect container-name<\/code> which provides details of network configuration, volumes, and labels in JSON format.\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\/13955\/how-to-check-if-the-docker-daemon-or-a-container-is-running\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Check If the Docker Daemon or a Container Is Running \u2013 CloudSavvy IT&#8221; Docker uses a daemon-based architecture where the CLI connects to a long-lived process running separately on your machine or a remote host. CLI commands won\u2019t work and your containers will usually go offline if the daemon stops. Here\u2019s how to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":330114,"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-330113","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\/330113","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=330113"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/330113\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/330114"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=330113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=330113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=330113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}