Docker Can’t Connect to the Docker Daemon? Here’s How to Fix It

If you’re working with Docker and encounter the error:

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

You’re not alone. This is one of the most common issues Docker users face—especially on fresh installations or after a system restart.

In this blog, we’ll explore why Docker can’t connect to the daemon, and how to fix it across common platforms like Linux, macOS, and Windows.


💡 What Does This Error Mean?

This error means that the Docker CLI (docker) is trying to talk to the Docker daemon (dockerd), but the daemon is not running, inaccessible, or the current user doesn’t have permission to access it.


🛠 Common Causes and Fixes

✅ 1. Docker Daemon Is Not Running

On Linux systems, the Docker daemon must be started manually or via systemd.

Fix:

sudo systemctl start docker

To enable it at boot:

sudo systemctl enable docker

Check the status:

sudo systemctl status docker

✅ 2. Permission Denied on Docker Socket

If you’re getting a permission error, you may not belong to the docker group.

Error:

Got permission denied while trying to connect to the Docker daemon socket

Fix:

sudo usermod -aG docker $USER

Then log out and log back in (or run newgrp docker) for the change to take effect.


✅ 3. Missing or Corrupted Docker Socket File

Docker communicates via a Unix socket: /var/run/docker.sock. If this file is missing or corrupted, you’ll get a connection error.

Fix:

Restart the Docker daemon:

sudo systemctl restart docker

Or check if the socket file exists:

ls -l /var/run/docker.sock

Expected output:

srw-rw---- 1 root docker 0 Jul 2 12:34 /var/run/docker.sock

✅ 4. Running Docker with sudo Resolves the Error

If docker only works with sudo, it means your user isn’t part of the docker group.

Temporary workaround:

sudo docker ps

Recommended long-term fix:

Add your user to the group (as shown above).


✅ 5. Docker Not Installed or Broken Installation

Verify if Docker is installed:

docker --version

If not found, reinstall Docker:

  • On Ubuntu:
sudo apt-get update
sudo apt-get install docker.io
  • On CentOS:
sudo yum install docker

✅ 6. Docker Desktop Not Running (macOS/Windows)

If you’re using Docker Desktop on macOS or Windows, make sure the Docker app is running.

  • Open Docker Desktop from your applications.
  • Wait for it to initialize fully before running CLI commands.
  • Check for any errors inside Docker Desktop’s GUI.

📄 Bonus: Diagnose with docker info

Run:

docker info

This command provides useful output to understand whether the daemon is reachable and what’s configured.


📝 Conclusion

The “cannot connect to Docker daemon” error usually boils down to one of three things: the daemon isn’t running, the user lacks permissions, or the environment is misconfigured. The good news? Each of these issues is easy to fix once you know what to check.


🔑 Quick Checklist

IssueSolution
Daemon not runningsudo systemctl start docker
Permission deniedsudo usermod -aG docker $USER
Broken socket filesudo systemctl restart docker
Docker Desktop not started (Win/Mac)Open Docker Desktop and wait
CLI works only with sudoAdd user to docker group
Sharing Is Caring:

Leave a Comment