Docker: Cannot Connect to the Docker Daemon – Fix Guide
If you’ve ever encountered the error message:
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 Docker-related errors, especially for developers new to containerization or those working on Linux-based environments. The good news? It’s usually a simple fix—if you know where to look.
In this guide, we’ll walk you through what causes this error, how to troubleshoot it step-by-step, and how to prevent it from happening again. Whether you’re running Docker on Ubuntu, macOS, WSL2, or even inside CI pipelines, we’ve got you covered.
What Does “Cannot Connect to the Docker Daemon” Mean?
This error means the Docker CLI (docker) cannot reach the Docker daemon process (dockerd). The Docker daemon is the engine that does all the heavy lifting — building, running, and managing containers.
The CLI and the daemon usually communicate over a Unix socket (/var/run/docker.sock) or via TCP on Windows/macOS. When this connection is broken or the daemon isn’t running, you get the error.
Common Causes of the Error
Let’s break down the most frequent reasons behind this issue:
- Docker daemon is not running
- Permission issues accessing the Docker socket
- Missing Docker group membership
- Systemd not starting Docker correctly
- WSL2 integration misconfigured (Windows users)
- Wrong Docker context
- Corrupted or missing Docker socket
🔧 Step-by-Step Fixes
Let’s explore the most reliable solutions depending on your system.
✅ 1. Check If the Docker Daemon Is Running
The most common fix is simply starting the Docker daemon.
On Linux (Ubuntu/Debian/CentOS):
sudo systemctl start dockerTo check the status:
sudo systemctl status dockerIf it’s not enabled to start at boot:
sudo systemctl enable dockerOn macOS or Windows (Docker Desktop):
Make sure Docker Desktop is running. Restart it from the system tray if needed.
✅ 2. Add Your User to the Docker Group (Linux)
Running docker as a non-root user without being in the Docker group causes permission errors.
Check Current Groups:
groupsAdd Your User to the Docker Group:
sudo usermod -aG docker $USERThen, log out and log back in (or reboot) to apply the changes.
💡 Pro Tip: You can verify with
groups $USERthat you’re part of thedockergroup.
✅ 3. Check Docker Socket Permissions
The Docker socket is located at:
/var/run/docker.sock
Check permissions:
ls -l /var/run/docker.sock
Output example:
srw-rw---- 1 root docker 0 Aug 6 12:34 /var/run/docker.sock
Make sure the group is docker and your user is part of it. If not, fix permissions (with caution):
sudo chown root:docker /var/run/docker.sock
sudo chmod 660 /var/run/docker.sock✅ 4. Restart the Docker Daemon
If Docker is misbehaving, a restart often helps.
sudo systemctl restart dockerOr, on Docker Desktop (macOS/Windows), use the restart button in the UI.
✅ 5. WSL2 Fix (Windows-Specific)
If you’re using WSL2, and get this error inside the terminal:
- Open Docker Desktop → Settings → Resources > WSL Integration
- Ensure your distro (e.g., Ubuntu) is enabled for Docker
- Reboot WSL with:
wsl --shutdownThen reopen your terminal and try again.
✅ 6. Switch Docker Context
If you recently used docker context, you might be on a remote or broken context.
Check your current context:
docker context lsSwitch back to default:
docker context use default✅ 7. Verify Docker Installation
Sometimes, Docker is simply not installed or the installation is broken.
To check version:
docker --versionIf it says “command not found,” install Docker using the official guide:
🛑 Still Not Working? Try These Advanced Fixes
If none of the above work:
Reinstall Docker:
sudo apt purge docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker
sudo apt install docker-ce⚠️ Be cautious: this will remove all containers, volumes, and images.
Check for Firewall/Security Software:
Security tools like AppArmor, SELinux, or firewalls might block Docker. Try disabling them temporarily for debugging.
Inspect Docker Logs:
journalctl -u docker.serviceLook for any fatal errors or misconfigurations.
🧪 Test If It’s Fixed
After applying fixes, run:
docker run hello-worldIf this works and prints a welcome message, you’re back in business!
🛡️ How to Prevent This Error in the Future
- Enable Docker at startup using
systemctl enable docker - Keep your Docker installation updated
- Avoid running Docker commands with
sudounnecessarily - Use
docker-composeonly after confirming Docker is healthy
🤔 Frequently Asked Questions
Q: Why do I need to use sudo with Docker?
By default, Docker needs root permissions. Adding your user to the docker group removes that need, but doing so can have security implications. Use it only on trusted systems.
Q: Is this error common in CI/CD pipelines?
Yes. CI runners (e.g., GitLab, GitHub Actions) often run in containers or isolated environments. Ensure the Docker daemon is available and properly mounted if using docker-in-docker.
Q: What if Docker was working and suddenly broke?
Likely causes include:
- A recent system update
- Corrupted Docker socket
- Unintentional group/user changes
✅ Summary
The “Cannot connect to the Docker daemon” error is frustrating—but fixable. Here’s a quick checklist:
| Fix Step | Command |
|---|---|
| Start Docker | sudo systemctl start docker |
| Add User to Docker Group | sudo usermod -aG docker $USER |
| Restart Docker | sudo systemctl restart docker |
| Check Socket | ls -l /var/run/docker.sock |
| Use Correct Context | docker context use default |
Once Docker is properly running, you should be able to build and run containers without issue.
👍 Final Thoughts
Docker is powerful, but like any tool, it requires proper setup. This guide should help you resolve the “Cannot connect to the Docker daemon” issue quickly and confidently. Bookmark it—you’ll probably run into this again someday.

