Permission denied on /var/run/docker.sock: the safe fix

"Got permission denied while trying to connect to the Docker daemon socket" means your user can't use Docker's socket. How to fix it with the docker group, why chmod 666 is a bad idea, and what to do for monitoring agents, CI runners and WSL.

· 5 min read · By the Spot Downtime team

You run a Docker command, or a tool that talks to Docker, and get this:

text
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock:
Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.47/containers/json": dial unix /var/run/docker.sock: connect: permission denied

Docker itself is fine. The Docker CLI, and every tool built on it, talks to the Docker daemon through a Unix socket, /var/run/docker.sock. That socket belongs to root and the docker group, and your user is in neither.

bash
ls -l /var/run/docker.sock
# srw-rw---- 1 root docker 0 Nov  5 09:12 /var/run/docker.sock
id
# uid=1000(alex) gid=1000(alex) groups=1000(alex),27(sudo)   <- no "docker"

Fix it for your own user

  1. Add yourself to the docker group:
    bash
    sudo usermod -aG docker $USER
  2. Start a new login session so the group applies: log out and back in, or open a new SSH connection. For the current shell only, newgrp docker works too.
  3. Check: docker ps runs without sudo.

If usermod says the group doesn't exist, create it with sudo groupadd docker and restart Docker (sudo systemctl restart docker) so the socket is created with that group.

The docker group is root, in practice

Anyone who can use the socket can start a container that mounts the host's whole filesystem, so the docker group is as powerful as root. Add people and services you'd trust with root, and nobody else. On shared machines, consider rootless Docker, where each user runs their own daemon.

Don't chmod 666 the socket

sudo chmod 666 /var/run/docker.sock makes the error disappear and gives every user and every process on the machine root, including a compromised web app. It also doesn't last: Docker recreates the socket with its usual permissions when it restarts, so the error comes back after the next reboot. Use the group instead.

When a service, not you, gets the error

Services run as their own users, so your group membership doesn't help them. Add the service's user to the group and restart the service, since a running process keeps the groups it started with:

bash
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins
  • systemd services can get the group without changing the user: SupplementaryGroups=docker in the unit file.
  • Containers that manage Docker (CI runners, Portainer, Traefik) need the socket mounted with -v /var/run/docker.sock:/var/run/docker.sock and must run as a user in the socket's group, often with --group-add $(getent group docker | cut -d: -f3).

WSL and Docker Desktop

In WSL, the socket only exists in your Linux distribution when Docker Desktop's integration is on for it: Settings → Resources → WSL integration, turn on your distribution, then Apply & restart. Without it, the docker command you run may be the Windows one, and Linux tools find no socket at all.

For the Spot Downtime agent

The server agent reports your containers when it can read the socket. Because that needs the docker group, the install script only adds the agent's user to it when you ask, with --docker. Without it, the server's Containers table says No permission to read /var/run/docker.sock. Run the install command from the server's page again with the flag:

bash
curl -fsSL https://spotdowntime.com/install-agent.sh | sudo sh -s -- --token YOUR_TOKEN --docker

The agent itself only reads: it lists containers, inspects them and reads one-shot stats. It never starts, stops or changes anything. To stop it reporting containers, run the command with --no-docker instead, which also takes the agent out of the group.

Once containers show up, you can watch the ones that matter as their own monitors. See containers that keep restarting and what Docker exit codes mean for the problems they catch.

Get new guides by email

Practical posts on monitoring, outages, error fixes and on-call, when they're published. No spam.

Unsubscribe from any email with one click. See our privacy policy.

Keep reading