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.
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.
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.
### 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: ""image operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker
cannot open '/etc/passwd': Permission denied
How to fix 'cannot open: Permission denied' in Docker
Error response from daemon: failed to create the ipvlan port
How to fix 'failed to create the ipvlan port' in Docker
toomanyrequests: Rate exceeded for anonymous users
How to fix 'Rate exceeded for anonymous users' in Docker Hub