Nothing stops a development workflow faster than this error:
$ docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock.
Is the docker daemon running?
Or its variation when running as a non-root user:
permission denied while trying to connect to the Docker daemon socket at
unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json":
dial unix /var/run/docker.sock: connect: permission denied
This is one of the most common Docker errors on Linux VPS servers and development machines. Here’s the complete diagnostic and fix guide.
Root Cause #1: Docker Daemon Not Running
The most common cause — Docker’s background service (daemon) simply isn’t started.
Diagnose:
sudo systemctl status docker
Look for Active: inactive (dead) or Active: failed.
Fix:
# Start the daemon
sudo systemctl start docker
# Enable it to start automatically on boot
sudo systemctl enable docker
# Verify it's running
sudo systemctl status docker
# Should show: Active: active (running)
If systemctl start docker fails, check the logs:
sudo journalctl -u docker --no-pager -n 50
Common failure reasons in the logs:
- “failed to start daemon: error initializing graphdriver” → Corrupted Docker storage. Run
sudo rm -rf /var/lib/dockerand restart (⚠️ this deletes all images and containers). - “listen tcp 0.0.0.0:2376: bind: address already in use” → Another process is using Docker’s port. Check with
sudo ss -tlnp | grep 2376.
Root Cause #2: Permission Denied (Non-Root User)
On a fresh Docker installation, only root and members of the docker group can communicate with the Docker socket. If you’re running Docker as a regular user, you’ll get the permission denied error.
Diagnose:
# Check if your user is in the docker group
groups $USER
# If "docker" is not in the output, you're not in the group
Fix:
# Add your user to the docker group
sudo usermod -aG docker $USER
# Apply the group change WITHOUT logging out (creates a new shell session)
newgrp docker
# Verify
docker ps
If newgrp docker doesn’t work, fully log out and log back in via SSH. Group changes only apply to new login sessions.
Root Cause #3: Docker Socket File Missing or Wrong Permissions
Sometimes the socket file itself is missing or has incorrect ownership.
Diagnose:
ls -la /var/run/docker.sock
# Expected: srw-rw---- 1 root docker ...
# If missing or owned by wrong group, this is the issue
Fix: Recreate the socket by restarting Docker:
sudo systemctl stop docker
sudo systemctl stop docker.socket
sudo systemctl start docker.socket
sudo systemctl start docker
Fix: Manually correct permissions (temporary, will reset on restart):
sudo chmod 666 /var/run/docker.sock
For a permanent permission fix, ensure the socket file is owned by root:docker via the systemd service configuration:
sudo nano /lib/systemd/system/docker.socket
Verify the [Socket] section contains:
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
Reload and restart:
sudo systemctl daemon-reload
sudo systemctl restart docker
Root Cause #4: Docker Installed via Snap (Ubuntu)
If you installed Docker via sudo snap install docker instead of the official Docker repository, the daemon behaves differently and often has socket path conflicts with the apt-installed version.
Diagnose:
snap list | grep docker
Fix: Remove the snap version and install from the official Docker repository:
sudo snap remove docker
# Install from official Docker repo
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
Root Cause #5: Context Misconfiguration (Docker Desktop)
If you’re using Docker Desktop on a developer machine alongside the CLI, Docker contexts can get confused:
# List all Docker contexts
docker context ls
# Switch to the default context
docker context use default
For containerized WordPress or web app environments that also use Redis, see our guide on configuring Redis object caching for WordPress — which covers Docker Compose Redis container setups in detail. For general container networking issues, also see fixing Docker bind address already in use.
Quick Diagnostic Checklist
Run through these in order before diving deep:
# 1. Is the daemon running?
sudo systemctl is-active docker
# 2. Is your user in the docker group?
groups | grep docker
# 3. Does the socket exist with correct permissions?
ls -la /var/run/docker.sock
# 4. Any errors in the daemon log?
sudo journalctl -u docker -n 20 --no-pager
Conclusion
The “Cannot connect to Docker daemon” error almost always has one of five root causes: the daemon isn’t running, the user lacks group permissions, the socket has wrong permissions, there’s a snap/apt conflict, or a context misconfiguration. Working through the diagnostic checklist above will resolve the issue in under 5 minutes in the vast majority of cases.
Ensure your Docker daemon has adequate system resources with a Pakistan-hosted cloud VPS.
