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:
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 deniedDocker 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.
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
- Add yourself to the
dockergroup:bashsudo usermod -aG docker $USER - 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 dockerworks too. - Check:
docker psruns withoutsudo.
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
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:
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins- systemd services can get the group without changing the user:
SupplementaryGroups=dockerin the unit file. - Containers that manage Docker (CI runners, Portainer, Traefik) need the socket mounted with
-v /var/run/docker.sock:/var/run/docker.sockand 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:
curl -fsSL https://spotdowntime.com/install-agent.sh | sudo sh -s -- --token YOUR_TOKEN --dockerThe 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.
Keep reading
- Docker · Servers · TroubleshootingDocker exit codes explained: 0, 1, 125, 126, 127, 137, 139 and 143What each Docker container exit code means, how to tell a crash from a clean stop, why 137 is either out of memory or docker stop, and the commands that show what happened.November 5, 2026 · 6 min read
- Docker · Servers · TroubleshootingDocker container keeps restarting? How to find out whyA container stuck in "Restarting (1)" crashes as soon as it starts and Docker keeps bringing it back. How to read its logs between restarts, pause the loop to debug it, and fix the usual causes.November 5, 2026 · 6 min read