How to fix Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? in Docker
This error occurs when the Docker client cannot communicate with the Docker daemon. The fix typically involves starting the Docker service or fixing permission issues.
Quick fix
Fixes Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
sudo systemctl status docker- Check if Docker daemon is running
- Start the Docker service
- Enable Docker to start on boot
- Fix permission issues (Linux)
sudo systemctl status dockerCannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
What this error means
The "Cannot connect to the Docker daemon at unix:///var/run/docker.sock" error indicates that the Docker CLI (command-line interface) is unable to establish a connection with the Docker daemon (dockerd). The Docker daemon is a background service that manages Docker containers, images, networks, and volumes. The Docker client communicates with the daemon through a Unix socket located at /var/run/docker.sock. When this socket is unavailable—either because the daemon isn't running, the socket file doesn't exist, or your user lacks permission to access it—you'll encounter this error. This is one of the most common Docker errors, especially on Linux systems after installation or system reboots. On Windows and macOS, it typically means Docker Desktop isn't running.
Typical symptoms
- Any docker command (docker ps, docker run, docker build) fails with the same error message
- Docker commands work with sudo but fail without it
- Docker Desktop application is not running (Windows/macOS)
- The Docker service shows as inactive or failed in systemctl status
- CI/CD pipelines fail at the first Docker command
- The file /var/run/docker.sock does not exist
Common causes
- Docker daemon (service) is not running
- Docker Desktop is not started (Windows/macOS)
- User lacks permission to access the Docker socket
- Docker was not configured to start on boot
- WSL integration is disabled in Docker Desktop settings
- DOCKER_HOST environment variable is set incorrectly
- Docker installation is incomplete or corrupted
- Systemd or containerd service dependency failed
- The docker.socket systemd unit needs to be restarted
How to fix "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"
First, verify the status of the Docker service:
sudo systemctl status dockerIf the output shows "inactive (dead)" or "failed", the daemon is not running. On older systems without systemd:
sudo service docker statusIf the Docker daemon is not running, start it with:
sudo systemctl start dockerOr on older init systems:
sudo service docker startVerify it's running:
docker infoTo prevent this issue after reboots, enable the Docker service to start automatically:
sudo systemctl enable docker.service
sudo systemctl enable containerd.serviceIf Docker works with sudo but not without, add your user to the docker group:
sudo usermod -aG docker $USERImportant: You must log out and log back in for the group changes to take effect. Alternatively, run:
newgrp dockerVerify your group membership:
groupsOn Windows or macOS, the Docker daemon runs inside Docker Desktop. Start the Docker Desktop application:
- Windows: Search for "Docker Desktop" in the Start menu and launch it
- macOS: Open Docker from Applications or use Spotlight (Cmd + Space, type "Docker")
Wait for the Docker icon in the system tray/menu bar to show "Docker Desktop is running".
If using Docker Desktop with WSL 2 and the error appears in your WSL terminal:
1. Open Docker Desktop settings (click the gear icon)
2. Go to Resources > WSL Integration
3. Ensure "Enable integration with my default WSL distro" is checked
4. Enable integration for your specific distro (e.g., Ubuntu)
5. Click Apply & Restart
Also check Settings > General > "Use the WSL 2 based engine" is enabled.
An incorrectly set DOCKER_HOST variable can cause connection issues:
echo $DOCKER_HOSTIf it returns a value (and you're not intentionally using a remote Docker host), unset it:
unset DOCKER_HOSTTo make this permanent, check and remove any DOCKER_HOST lines from ~/.bashrc, ~/.zshrc, or ~/.profile.
Sometimes the Docker socket needs to be restarted separately:
sudo systemctl restart docker.socket
sudo systemctl restart dockerThis has resolved issues for users on Ubuntu 22.04 and later.
If none of the above solutions work, consider reinstalling Docker:
# Remove existing installation
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Remove leftover files
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
# Reinstall following official docs
# https://docs.docker.com/engine/install/Warning: This will remove all containers, images, and volumes. Back up important data first.
Advanced notes
### Rootless Docker
If you're running rootless Docker (Docker without root privileges), the socket path is different. Check if your socket exists at:
ls -la $XDG_RUNTIME_DIR/docker.sock
# or
ls -la ~/.docker/run/docker.sockYou may need to set DOCKER_HOST accordingly:
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock### Docker Context
Docker supports multiple contexts for connecting to different Docker daemons. Check your current context:
docker context ls
docker context use default### Container/VM Issues
On Docker Desktop for Mac/Windows, the daemon runs inside a lightweight VM. If this VM is in a bad state:
1. Quit Docker Desktop completely
2. On Mac: rm -rf ~/Library/Containers/com.docker.docker
3. Restart Docker Desktop
### CI/CD Pipelines
In GitLab CI or similar environments using Docker-in-Docker (DinD), you may need to configure:
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""Frequently asked questions
- What does "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is" mean?
- sock" error indicates that the Docker CLI (command-line interface) is unable to establish a connection with the Docker daemon (dockerd). The Docker daemon is a background service that manages Docker containers, images, networks, and volumes. sock.
- How do I fix "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is"?
- This error occurs when the Docker client cannot communicate with the Docker daemon. The fix typically involves starting the Docker service or fixing permission issues.
- What causes "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is"?
- Docker daemon (service) is not running Docker Desktop is not started (Windows/macOS) User lacks permission to access the Docker socket
- Is the "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Docker Official Documentation
- 📖Troubleshooting the Docker daemon - Docker Docs(Official Docs)
- 📖Post-installation steps for Linux - Docker Docs(Official Docs)
- 💬
- 💬How to fix Docker: Permission denied - Stack Overflow(Stack Overflow)
- 🐙
- 🐙