If you are experiencing “Cannot Connect to the Docker Daemon” errors, it is likely that your docker daemon is not up and running. To troubleshoot this issue, first check to see if your docker daemon is running on your system. If it is not, you can start it by running the following command: sudo docker-compose up
Docker is one of the leading platforms for building and running software containers. It comes with everything you need to use containers on either a single host or multiple distributed nodes in Swarm mode.
Docker has a daemon-based architecture. The software that’s responsible for creating and starting containers is independent of the CLI process that accepts your commands. This means you’ll see errors in the CLI if you try to run commands without an active daemon connection. In this article, we’ll share some methods for troubleshooting these frustrating messages.
Problem Symptoms
The Docker CLI is reliant on a daemon connection being available. It interacts with the daemon using API calls. When the configured daemon’s inaccessible, docker commands like docker ps, docker run, and docker build will show an error message similar to this one:
This reveals that the CLI tried to communicate with the Docker daemon using the /var/run/docker.sock Unix socket. The socket’s not open so the connection failed.
1. Check the Docker Daemon Service Is Running
The Docker daemon is usually managed by a systemd service that automatically starts Docker after your host reboots. You can begin troubleshooting by checking whether this service is running:
The service should report Active: active (running) if the daemon is running. The example above shows inactive (dead) which means the daemon has stopped.
Start Docker using the following command:
Now you should be able to run docker CLI commands successfully.
You might find that Docker stays in the stopped state after you reboot your machine. You can solve this by enabling the service, allowing systemd to start it automatically:
The daemon-reload command instructs systemd to reload its configuration to apply the change.
2. Start the Daemon Manually
You might sometimes use a system that doesn’t have the Docker service installed. You can manually start the Docker daemon using the dockerd command. This usually needs to be run as root.
Docker will remain accessible for as long as the command’s running. Use Ctrl+C to stop the daemon.
3. Checking the CLI Is Targeting the Correct Daemon
Problems can occur when the CLI is trying to connect to a remote Docker daemon instance. This is usually the cause when the error message shows a TCP address:
In this example, the docker CLI is trying to contact the Docker daemon at 0.0.0.0:2375 using TCP, instead of the local Unix Docker socket. This will fail if the Docker daemon’s TCP support is disabled or the specified host is inaccessible on the network.
You can usually resolve this by switching to the correct Docker CLI context for the daemon connection you want to use:
You can list all the available contexts and the daemon endpoints they connect to with the context ls command:
The currently selected context is highlighted with an asterisk.
Unexpected values in the DOCKER ENDPOINT column are usually caused by the DOCKER_HOST environment variable being set. You’ll see a warning when this is the case:
The presence of the DOCKER_HOST environment variable in your shell overrides the endpoint defined by your selected context. In this example, docker commands will always target the daemon instance at tcp://1.2.3.4:2375.
This problem can be resolved by clearing the DOCKER_HOST variable:
Docker will now use the endpoint configured by your active context. This will be the default local Unix socket at /var/run/docker.sock unless you’ve manually set up a custom context.
4. Permissions Issues
Incorrect user permissions on Docker’s socket are another common cause of daemon connection issues. This kind of problem usually shows a slightly different error message:
This happens when your Unix user account lacks permission to interact with the socket that exposes the Docker API. Adding yourself to the docker group is the best practice way to resolve this problem:
You’ll need to open a new shell window or logout and back in again for this change to take effect. You should now be able to run docker commands without running into permissions problems.
Summary
“Cannot connect to the Docker daemon” appears when the Docker CLI is unable to communicate with a Docker daemon instance using your current configuration. This is often because the Docker daemon service has been stopped or disabled. You could also be trying to connect to a remote Docker host that’s gone offline.
You should now be aware of the possible causes of this problem and the common ways to solve it. Troubleshoot the error by checking your Docker daemon settings, restarting the Docker service, and making sure your user account has permission to interact with Docker’s socket.