Fix "Cannot Connect to the Docker Daemon" Error

By 

•

Published on

•

8 min read

A terminal showing docker info beside a server with an unlit status lamp and a docker.sock nameplate

You run docker ps and see failed to connect to the docker API or Cannot connect to the Docker daemon. In both cases, the client could not reach the daemon at the address shown in the error.

Start with docker info. This guide shows how to use its output to find the right daemon, check whether it is running, and fix access to its socket. We tested the system-wide and rootless examples with Docker 29.10.1 on Debian 13.

Quick Reference

For a printable quick reference, see the Docker cheatsheet .

Check or fixCommand
Ask the daemon for informationdocker info
Show environment overridesenv | grep -E '^DOCKER_(HOST|CONTEXT)='
List CLI contexts and their endpointsdocker context ls
Check the system service and socketsudo systemctl status docker.service docker.socket
Read daemon logssudo journalctl -u docker.service -n 100 --no-pager
Inspect the local socketls -l /var/run/docker.sock
Check rootless Dockersystemctl --user status docker

Confirm the Exact Error

Run Docker’s diagnostic command from the same shell and user account that produced the error.

Terminal
docker info

When the server is unreachable, the output usually shows client details followed by an error. Here is what Docker 29.10.1 reports when the default socket is missing.

output
failed to connect to the docker API at unix:///var/run/docker.sock; check if the path is correct and if the daemon is running: dial unix /var/run/docker.sock: connect: no such file or directory

If the socket file still exists after the service stops, the same Docker version can report this message.

output
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Docker 28 and older also print this message when the socket file is missing.

The path tells you which socket the client tried. For these errors at /var/run/docker.sock, check the system service . A path under your home directory or /run/user/, or a remote address, points to a different Docker setup.

If the error says permission denied while trying to connect to the docker API instead, check the socket permissions . Docker 28 and older print permission denied while trying to connect to the Docker daemon socket for the same problem.

Check the Docker Endpoint

Docker contexts store the addresses of local, remote, rootless, and Desktop engines. Run these commands to see which settings this shell uses.

Terminal
env | grep -E '^DOCKER_(HOST|CONTEXT)='
docker context ls

If the first command prints nothing, neither DOCKER_HOST nor DOCKER_CONTEXT is set in this shell. docker context ls marks the active context with an asterisk and shows its endpoint.

Either environment variable can override the saved context. When both variables have values, DOCKER_HOST determines the endpoint. Even the default context uses that address while DOCKER_HOST is set.

To test the system-wide Docker Engine on this machine, pass its socket explicitly. This test leaves your saved context and shell settings in place.

Terminal
docker --host unix:///var/run/docker.sock info

If that works and you want to use the local Engine by default, clear any accidental overrides before selecting the context.

Terminal
unset DOCKER_HOST DOCKER_CONTEXT
docker context use default
docker info

If an override returns when you open a new terminal, check the shell configuration file that sets it, such as ~/.bashrc or ~/.profile. If you meant to use Docker Desktop for Linux, start Desktop and test its desktop-linux context with docker --context desktop-linux info. Docker Desktop and the system Engine manage their own images and containers.

Start the Docker Service

On a system-wide Docker Engine installation managed by systemd, check the service and its socket.

Terminal
sudo systemctl status docker.service docker.socket

If docker.socket is active, a client connection can start the daemon through systemd socket activation. To start an inactive docker.service directly, run this command.

Terminal
sudo systemctl start docker

Run docker info again and look for the server details. If you want the service to start at boot, enable it.

Terminal
sudo systemctl enable docker

If systemd reports Unit docker.service could not be found, check whether you installed only the client or use Docker Desktop or rootless Docker. If you installed Docker as a snap, run snap services docker and look for the docker.dockerd service. The Docker installation guides for Ubuntu 26.04 and Debian 13 cover the packages needed for a system-wide Engine.

Read the Docker Daemon Logs

If the service shows a failed state or exits as soon as you start it, read its recent log entries.

Terminal
sudo journalctl -u docker.service -n 100 --no-pager

Common causes include invalid JSON in /etc/docker/daemon.json, the same option defined in both that file and the systemd startup flags, an unavailable storage path, or no free disk space. Fix the first relevant error in the log instead of repeatedly restarting the service.

If you recently edited the daemon configuration, you can validate the file without starting Docker.

Terminal
sudo dockerd --validate --config-file=/etc/docker/daemon.json
output
configuration OK

configuration OK means Docker accepted the file. It can still fail to start if the systemd unit passes the same setting as a command-line flag. To see the startup flags, inspect the unit and its drop-ins.

Terminal
sudo systemctl cat docker.service

For example, the official packages on Ubuntu and Debian pass -H fd://. A hosts entry in daemon.json conflicts with that flag. If the journal reports a duplicate directive, keep the setting in one place. If you need to change the listener, see Docker’s guide to resolving startup conflicts .

Once you have corrected the cause, restart the service and check its status. A restart can stop running containers, so plan for downtime if this host is still serving workloads.

Terminal
sudo systemctl restart docker
sudo systemctl status docker

Run docker info again to confirm that the client can reach the daemon.

Fix Docker Socket Permissions

If the client reports a permission error on /var/run/docker.sock, run both checks against that exact socket. Your account and sudo can otherwise pick different contexts or environment settings.

Terminal
docker --host unix:///var/run/docker.sock info
sudo docker --host unix:///var/run/docker.sock info

If the second command still cannot connect, check the service even if the socket file exists. If only the second command succeeds, inspect the socket’s ownership and compare its group with your current session’s groups.

Terminal
ls -l /var/run/docker.sock
id -nG

The official Docker Engine packages normally give the docker group access to the socket. If the socket belongs to that group and you administer this host, add your account to the group.

Warning
Membership in the docker group grants root-level control of the host. Add only trusted administrator accounts. Making the socket writable by everyone with chmod 666 gives every local user control of the daemon.
Terminal
sudo usermod -aG docker "$USER"

Log out and back in so the shell receives the new group membership. To test it right away, start a shell with the new group and rerun the same socket check.

Terminal
newgrp docker
docker --host unix:///var/run/docker.sock info

Use exit when you are done with the newgrp shell. If the socket has unexpected ownership, inspect the units that define how it is created.

Terminal
sudo systemctl cat docker.socket docker.service

With systemd socket activation, docker.socket sets SocketUser, SocketGroup, and SocketMode. The official packages use root, docker, and 0660. If a local drop-in sets the wrong values, correct the drop-in first. Then reload systemd, restart both units, and inspect the recreated socket. Do this during a maintenance window if the daemon is running containers.

Terminal
sudo systemctl daemon-reload
sudo systemctl restart docker.socket docker.service
ls -l /var/run/docker.sock

Start Rootless Docker

Rootless Docker runs as your user. If you installed it with systemd, check and start the user service.

Terminal
systemctl --user status docker
systemctl --user start docker

The setup tool normally creates a rootless context. Test that context explicitly.

Terminal
docker --context rootless info

Look for rootless under the server’s security options. The socket is normally at $XDG_RUNTIME_DIR/docker.sock, usually /run/user/<UID>/docker.sock. Once the test works, you can select rootless with docker context use rootless after clearing any accidental shell overrides.

Troubleshooting

The socket file does not exist
Confirm the path in the error. For the system-wide Engine, check docker.service and docker.socket. For rootless Docker, check the user service. If the path points into ~/.docker/desktop/, start Docker Desktop and check the desktop-linux context.

systemd reports that Docker was started too often
Correct the underlying error in the journal first. Run sudo systemctl reset-failed docker.service to clear the start limit, then try sudo systemctl start docker.service again.

The error occurs inside a container or CI job
The Docker client inside that environment still needs a daemon endpoint. Connect it to a remote daemon or deliberately mount the host socket when the security risk is acceptable. Mounting /var/run/docker.sock gives the container root-equivalent control of the host.

The error names a remote SSH or TCP endpoint
Check the address in docker context ls or DOCKER_HOST. If the endpoint is correct, verify that the remote host is reachable and its daemon is running. Use SSH or TLS to protect a remote Docker API.

Conclusion

Once docker info shows the expected server, rerun the command that failed from your original shell. Use the same user and context you normally use to manage those containers.

Tags

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page