Docker: permission denied while trying to connect to the Docker daemon socket
Docker is installed and running, but every command without sudo stops with a permission error on /var/run/docker.sock. Your user simply isn’t allowed to talk to the Docker daemon yet.
What the error means
The docker command is only a client. It sends every request to the Docker daemon through a Unix socket, normally /var/run/docker.sock. On Linux that socket belongs to root and the docker group:
$ ls -l /var/run/docker.sock
srw-rw---- 1 root docker 0 Nov 4 09:12 /var/run/docker.sock
The rw-rw---- part means only root and members of the docker group may connect (how to read permission strings). If your user is in neither, you get:
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
A different message, Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?, means the daemon isn’t running at all: start it with sudo systemctl start docker (and enable it to start at boot).
The fix, step by step
sudo groupadd docker # usually exists already; harmless if it does
sudo usermod -aG docker $USER # -a matters: without it you lose your other groups
newgrp docker # or log out and back in
id -nG # "docker" should now be in the list
docker run --rm hello-world
The most common reason it “still doesn’t work”: group changes only apply to new login sessions. An open terminal, a tmux session, an SSH connection or a VS Code remote server started before the change keeps the old groups. Close them all (for VS Code remote, kill the server) or reboot.
Why not chmod 666 or sudo everything?
- chmod 666 /var/run/docker.sock lets every user and every compromised process on the machine control Docker, which means mounting
/into a container and becoming root. It also resets when Docker restarts, so it fixes nothing for long. - The docker group is root-equivalent too. Only add people you would trust with sudo.
- sudo docker works, but files created in bind mounts end up owned by root and your
~/.docker/config.jsonlogins are ignored.
Safer: rootless Docker or Podman
Rootless mode runs a daemon as your own user, with its socket at $XDG_RUNTIME_DIR/docker.sock, so a container escape only reaches your account. Install the docker-ce-rootless-extras package and run dockerd-rootless-setuptool.sh install, then point the client at it with docker context use rootless. Podman is daemonless and rootless by default and accepts most docker commands.
Special cases
| Where | What’s going on | Fix |
|---|---|---|
| Container that mounts the socket (CI runners, Portainer, Traefik) | The user inside the container isn’t in a group with the socket’s group ID on the host | Add that numeric group: --group-add $(stat -c %g /var/run/docker.sock) |
| GitHub Actions self-hosted / Jenkins agent | The service user (e.g. jenkins) isn’t in docker, or the service wasn’t restarted | usermod -aG docker jenkins, then restart the agent service |
| Docker installed with snap | Snap’s socket and group handling differ | Create the group and add yourself, then sudo snap disable docker && sudo snap enable docker, or switch to the official packages |
| Docker Desktop on Linux, macOS or WSL | The client is pointed at the wrong context or the Desktop VM isn’t running | docker context ls and docker context use desktop-linux (or default); start Docker Desktop |
Wrong DOCKER_HOST | An old environment variable points at a socket you can’t use | echo $DOCKER_HOST; unset DOCKER_HOST |
Comparing group IDs between the host and a container? Run getent group docker on the host and id inside the container: the numbers must match.
Docker filling your disk? See docker system prune explained.
Git inside a container complaining about dubious ownership? See git dubious ownership. No sudo rights to add yourself to the docker group? See user is not in the sudoers file.
Questions
How do I run docker without sudo?
Add your user to the docker group with sudo usermod -aG docker $USER, then start a new login session (log out and in, or run newgrp docker). Remember that docker group membership is equivalent to root access.
I added myself to the docker group but it still says permission denied
Group membership is read at login. Close every terminal, tmux and SSH session (and any VS Code remote server) or reboot, then check that id -nG lists docker.
Is chmod 666 /var/run/docker.sock safe?
No. It lets any user or process on the machine control Docker, which is the same as giving them root, and the permissions reset whenever Docker restarts.
What is the difference between permission denied and 'Is the docker daemon running?'
Permission denied means the daemon is running but your user may not use its socket. 'Cannot connect to the Docker daemon ... Is the docker daemon running?' means nothing is listening, so start the docker service.
Published .