What the "Cannot connect to the Docker daemon" Error Means
The Cannot connect to the Docker daemon error (or docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?) means that the docker client utility (for example, the docker ps command) cannot establish a connection with the background process—the Docker daemon (dockerd).
The daemon is the service that manages all Docker objects: images, containers, networks, volumes. Without a running daemon, any docker command is useless. The error appears immediately after entering the command and typically does not include a long stack trace.
Common Causes
- The Docker service is stopped. The most frequent cause. The daemon is simply not running on the system.
- The service failed to start. Docker attempted to start but encountered a problem (e.g., port conflict, error in
daemon.jsonconfiguration, insufficient memory). - Docker is not configured for autostart. After a computer reboot, the service does not start automatically.
- Port conflict. If a TCP port (e.g.,
-H tcp://0.0.0.0:2375) is specified in/etc/docker/daemon.jsonor in the launch arguments, and that port is already occupied by another application, the daemon will fail to start. - Corrupted Docker files. Critical package files (binaries, configs) may have been damaged during an update or a crash.
- Insufficient user permissions. The user running
dockermay not have permission to access the/var/run/docker.socksocket (although this usually causesPermission deniedrather than "daemon not running," it can be related).
Solution 1: Start and Check Service Status via systemd
On modern Linux distributions (Ubuntu, Debian, CentOS 7+, RHEL 7+, Fedora), Docker is managed via systemd.
- Check the service status:
sudo systemctl status docker
Look for theActive:line. If it showsinactive (dead)orfailed— the service is not running. - Start the service:
sudo systemctl start docker - Enable autostart (so you don't have to start it manually after each reboot):
sudo systemctl enable docker
You will see a symbolic link being created. - Verify the daemon is running:
sudo systemctl is-active docker
The command should returnactive. - Try running a Docker command:
docker version
Ordocker ps
💡 Tip: If
systemctl start dockerfinishes instantly without errors, butstatusshowsfailed, check the logs:sudo journalctl -u docker.service --no-pager -n 50.
Solution 2: Diagnostics via systemd Logs
If the service fails to start, its logs will contain the reason for the failure.
- View the latest log entries for the Docker service:
sudo journalctl -u docker.service --no-pager -n 100
Look for lines starting withdocker[...]:or simply error messages (error,failed,cannot). - Common errors in logs and their solutions:
Error starting daemon: pid file found, ensure Docker is not running or delete /var/run/docker.pid— delete the lock file:sudo rm /var/run/docker.pidand try again.failed to start daemon: port is already allocated— port conflict. Find the process using the port (by default, for Unix sockets there is no conflict, but if TCP is used):sudo lsof -i :2375. Stop the conflicting process or change Docker's port in/etc/docker/daemon.json.Error initializing graphdriver: overlay— issue with the storage driver (overlay/overlay2). Often resolved by updating the kernel or switching the driver indaemon.json.
Solution 3: Check and Configure the daemon.json File
Invalid JSON in /etc/docker/daemon.json can prevent startup.
- Validate the file's syntax:
sudo cat /etc/docker/daemon.json | python3 -m json.tool > /dev/null && echo "JSON valid" || echo "JSON invalid"
If the output isJSON invalid, edit the file (sudo nano /etc/docker/daemon.json) and fix errors (extra commas, incorrect quotes). - Temporarily disable the configuration for testing:
sudo mv /etc/docker/daemon.json /etc/docker/daemon.json.bak sudo systemctl restart docker
If Docker starts after this — the problem is in the configuration. Restore your settings one by one, restarting the service after each change.
Solution 4: Check System Resources and Dependencies
The Docker daemon may require specific resources or kernel modules.
- Ensure the
overlaykernel module is loaded (for the overlay2 driver):lsmod | grep overlay
If the output is empty, load the module:sudo modprobe overlay. - Check if there is enough space on the
/varpartition. Docker stores images and data there. If space runs out, the daemon may fail to start:df -h /var - For RHEL/CentOS-based distributions: Ensure the
containerd.iopackage is installed and running:sudo systemctl status containerd
Solution 5: Full Reinstallation of Docker (if other solutions fail)
- Remove Docker packages:
For Debian/Ubuntu:
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin sudo rm -rf /var/lib/docker /etc/docker
For RHEL/CentOS/Fedora:sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin sudo rm -rf /var/lib/docker /etc/docker - Reinstall Docker by following the official guide for your distribution. This ensures you get correct dependencies and configuration files.
Prevention
- Always enable autostart: After the initial Docker installation, immediately run
sudo systemctl enable docker. - Monitor kernel updates: After a kernel update (especially on RHEL-compatible distributions), a reboot may be required. Check Docker's status after rebooting.
- Do not edit
/etc/docker/daemon.jsonwithout validating syntax. Use a JSON validator or thepython3 -m json.toolcommand. - Regularly check disk space, especially in
/var/lib/docker. Container logs can grow very quickly. - Avoid running Docker manually (
dockerd &). Always usesystemctlso systemd can properly manage the process and capture its logs.