LinkedIn Icon

2022-06-15 14:44:48 By : Ms. Sherry Lee

Join 425,000 subscribers and get a daily digest of news, geek trivia, and our feature articles.

By submitting your email, you agree to the Terms of Use and Privacy Policy.

James Walker is a contributor to How-To Geek DevOps. He is the founder of Heron Web, a UK-based digital agency providing bespoke software development services to SMEs. He has experience managing complete end-to-end web development workflows, using technologies including Linux, GitLab, Docker, and Kubernetes. Read more...

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’t work and your containers will usually go offline if the daemon stops.

Here’s how to check whether Docker’s daemon is up so you can diagnose issues with containers and the docker command. When the daemon’s not running, you’ll see a “can’t connect to Docker daemon” message each time you use the docker CLI.

You can check Docker’s status with systemctl on distributions that use Systemd for service management. This covers the majority of popular operating systems including Debian, Ubuntu, CentOS, and Red Hat.

Check what’s displayed under “Active.” If you see active (running) in green, the Docker daemon is running and your containers should be up.

An active state of inactive indicates the service has stopped. Try to bring it up by running sudo systemctl start docker. The status should change to active (running) after the daemon starts.

If you see a status of failed in red, the daemon couldn’t start due to an error. You should review the service’s startup logs shown later in the systemctl command output as these usually contain hints that let you work out what went wrong.

When there’s no obvious resolution available, manually start the daemon in debugging mode to get more information on its startup routine.

Rebooting your host machine or restarting the Docker service with systemctl restart docker can help alleviate transient issues too.

Another way to check for a running Docker daemon is by inspecting its process ID file. The daemon writes its process ID to /var/run/ each time it starts up. When this file exists, Docker should be running and ready for CLI connections.

You can use this technique to create programmatic scripts that check whether the daemon’s alive. Reading the file gives you the ID which you can use with tools like top to get more information about the Docker process:

You can also get the process ID with thepidofcommand. This accepts a process name and returns the first matching ID:

There’s an active Docker daemon on your machine if top matches a dockerd process. This can be more reliable than looking for – if the daemon crashes, could get left behind after the process is gone.

The daemon will refuse to restart when a PID file is present. This could get you stuck in a restart loop if the file’s actually orphaned from a previous run. You’ll see this message when running dockerd:

Use pidof dockerd to make sure Docker’s actually stopped. Proceed if the command emits no output, confirming there’s no running process.

Run sudo rm /var/run/ to delete the old process ID file. The daemon should now start successfully next time you run dockerdor service docker start.

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’s already running.

The status of individual containers is accessed via the docker ps command. This emits a table containing the details of all currently running containers.

Combine the docker ps command with grep to easily check whether a specific container is running by ID or name:

Now the output will be filtered to show the container you’ve selected. There’ll be no records if the container isn’t running.

Stopped containers are displayed using docker ps -a. A stopped container can be started with the docker start command:

The container will then move into the regular docker ps output. You can stop it again with docker stop my-container.

You’ve got several options to consider when you want to know whether Docker is running. There’s your operating system’s service manager, the file, and regular process inspection tools such as top and pidof.

When it comes to individual containers, docker ps provides the list of everything that’s currently running on your host. More comprehensive information on the state of any container can be gleaned with docker inspect container-name which provides details of network configuration, volumes, and labels in JSON format.

The Best Free Tech Newsletter Anywhere

By submitting your email, you agree to the Terms of Use and Privacy Policy.