How to Fix “Cannot Connect to the Docker Daemon” Errors on a VPS

You type docker ps on your VPS, hit Enter, and instead of a container list you get: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? The message looks alarming, but it rarely means Docker is broken beyond repair. In most cases the cannot connect to the docker daemon error means the daemon simply is not running, your user lacks permission to reach the socket, or a small configuration mistake points the client at the wrong place. This guide works through the causes in the order you should check them, with the exact commands for each fix.

What “Cannot Connect to the Docker Daemon” Actually Means

Docker has two parts: the client you type commands into, and the daemon (dockerd) that does the real work of pulling images, starting containers, and managing networks. The client talks to the daemon through a Unix socket, usually /var/run/docker.sock. When the client cannot reach that socket, it prints the error above. The error itself does not tell you why the connection failed, so the fix starts with finding out which side of the conversation is at fault. Work through the checks below in order; most people find the problem in the first three.

1. Check Whether the Docker Daemon Is Running

The most common cause is also the simplest: a docker daemon not running at all. A reboot, a failed update, or an out-of-memory kill can stop it, and nothing restarts it automatically unless you configured that. Check its status first:

sudo systemctl status docker

If the output says inactive (dead), start it and check again:

sudo systemctl start docker
sudo systemctl status docker --no-pager

If it starts cleanly, run docker ps again. If the daemon keeps stopping after a reboot, enable it so it starts with the server:

sudo systemctl enable docker

On a server without systemd, check how Docker was installed and start it the way that install expects, for example sudo service docker start on older SysV setups. If the daemon starts but your containers do not come back with it, that is a separate problem: containers only restart on boot if they were created with a restart policy, which is why it pays to set a restart policy when you create containers instead of relying on the daemon alone.

2. Start or Restart the Daemon When It Is Stuck

Sometimes the daemon shows as active but still does not answer. A half-failed start, a wedged storage driver, or a process that died without systemd noticing can leave it in that state. A clean restart clears it:

sudo systemctl restart docker
docker ps

Restarting the daemon stops every running container unless those containers have a restart policy, so do this in a maintenance window if your VPS hosts anything live. If the restart hangs for more than a minute, check for a zombie dockerd process:

ps aux | grep dockerd
sudo kill -9 <PID>

Then start the service again. If the daemon refuses to stay up after a restart, skip ahead to the log section below instead of restarting it in a loop.

3. Fix Docker Socket Permission Problems

If the daemon is running but you still see the error, the likely cause is permissions. By default only root and members of the docker group can talk to /var/run/docker.sock. Running as a normal user without that membership produces the same “cannot connect” message, which is often misread as a docker.sock permission denied problem in disguise. Check the socket first:

ls -l /var/run/docker.sock
groups $USER

You should see something like srw-rw---- 1 root docker. If your username is not in the docker group, add it:

sudo usermod -aG docker $USER
newgrp docker

The newgrp command applies the change to your current shell. If you open a fresh SSH session instead, the new group membership applies there too. Do not fix this by running chmod 777 on the socket. That hands any local user full control of Docker, which is effectively root access, and the permission resets on the next daemon restart anyway. If you manage several services on the same host, consider running your monitoring stack as a non-root user too; our guide to installing Uptime Kuma on a VPS with Docker shows the same group pattern in a real setup.

4. Check DOCKER_HOST and Your Active Context

The Docker client connects to whatever DOCKER_HOST says, and a stale variable or context can send it somewhere the daemon is not listening. This happens often after following a tutorial that sets DOCKER_HOST for a remote host, or after switching contexts and forgetting to switch back. Check both:

echo $DOCKER_HOST
docker context ls

If DOCKER_HOST is set to a TCP address or a path that does not exist, unset it for the current session and try again:

unset DOCKER_HOST
docker ps

If the variable keeps coming back, look for it in ~/.bashrc, ~/.profile, or /etc/environment and remove the line. For contexts, make sure the asterisk marks the default context, or the one that points at your local socket:

docker context use default

A mismatch here produces the identical error message as a stopped daemon, which is why this check belongs before you start reinstalling anything.

5. Free Disk Space and Clear a Stuck Daemon State

A full disk can stop the daemon from starting or from accepting new connections, and Docker itself is often the thing that filled the disk. Old images, stopped containers, and build cache accumulate quietly until the root filesystem hits 100 percent. Check before you assume anything else:

df -h /
docker system df

If the disk is full, reclaim space with a prune. The safe version removes only unused objects:

docker system prune -a --volumes

Read the prompt before confirming: --volumes deletes anonymous volumes, so skip that flag if any of them hold data you need. For a repeatable cleanup routine that goes beyond a one-off prune, see our walkthrough on how to clean up old Docker images and free disk space on your VPS. If the daemon will not start at all and you suspect corrupted state, check the storage directory under /var/lib/docker for a lock file left by a killed process, and remove only lock files, never the directory contents, before starting the service again.

6. Read the Daemon Logs When It Refuses to Start

When every check above passes and the daemon still will not answer, the logs hold the answer. A docker daemon failed to start event usually leaves a clear reason in the journal: a bad option in /etc/docker/daemon.json, a storage driver the kernel does not support, or a port conflict on the default bridge network. Pull the recent log entries:

sudo journalctl -u docker --no-pager -n 100

Look for lines marked level=fatal or level=error near the end. The most frequent culprits:

  • Invalid JSON in daemon.json: one trailing comma breaks the whole file. Validate it with python3 -m json.tool /etc/docker/daemon.json and fix the syntax.
  • Storage driver mismatch: a daemon.json that asks for a driver your kernel lacks, such as devicemapper on a modern kernel. Remove the storage-driver line and let Docker pick its default.
  • Conflicting network: another service already owns the bridge subnet. Change the bip value in daemon.json or stop the conflicting service.

After any change to daemon.json, reload systemd and restart the daemon:

sudo systemctl daemon-reload
sudo systemctl restart docker

If the logs show nothing at all, the service may be failing before it writes anything. Try starting dockerd directly in the foreground to see the raw output:

sudo dockerd --debug

Stop it with Ctrl+C once you have the error, then fix the cause and start the service normally. Once the daemon is healthy again, add a lightweight check so you hear about the next failure before your users do. A simple container health check plus an uptime monitor catches a dead daemon within minutes; the steps are covered in our guide to setting up health checks for Docker containers on a VPS.

Keep It From Coming Back

The fix that lasts is rarely a single command. Enable the service so it survives reboots, keep your user in the docker group, watch disk usage before it hits 100 percent, and avoid hand-editing daemon.json without validating the JSON first. A five-minute check after every Docker or system update, running docker ps and df -h, catches most of these failures while they are still small. If the same error returns after you fix it, compare the journal entries from the two failures: a repeat of the same fatal line points at a configuration problem, while a different line each time points at resource pressure on a VPS that is simply too small for the stack it runs.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.