| title | Docker Permission Denied on the Docker Socket | |||||
|---|---|---|---|---|---|---|
| slug | docker-permission-denied-docker-socket | |||||
| technologies |
|
|||||
| severity | medium | |||||
| tags |
|
|||||
| related |
|
|||||
| last_reviewed | 2026-06-27 |
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.45/containers/json": dial unix /var/run/docker.sock: connect: permission denied
Got permission denied while trying to connect to the Docker daemon socket
The Docker daemon socket /var/run/docker.sock is owned by root and the
docker group, with mode 0660. The CLI client connects to it as the invoking
user. When that user is neither root nor a member of the docker group, the
kernel denies the connect() on the socket and the client reports permission
denied. Unlike "cannot connect", the daemon is running fine — the caller simply
isn't authorized to talk to it.
- docker (Unix socket, group permissions)
medium — Docker works for privileged users, so this is usually a per-user or CI-runner setup gap rather than an outage. Note that granting socket access is effectively granting root on the host, so it is also a security-relevant decision.
- The user is not in the
dockergroup. - The user was added to
dockerbut their current shell/session predates the change, so the new group membership hasn't taken effect. - A CI runner or service runs as an unprivileged user without group access.
- The socket was bind-mounted into a container whose process UID has no access.
Group membership is evaluated at login/session creation. Running
usermod -aG docker $USER updates /etc/group, but the running shell still
carries the old supplementary-group set from when it started. The kernel checks
the socket's 0660 root:docker permissions against that stale set and denies the
connection until a fresh session is started. So a "permission denied" right after
adding the user is almost always a not-re-logged-in problem, not a misconfiguration.
# Socket ownership and mode (expect: srw-rw---- root docker)
ls -l /var/run/docker.sock
# Groups the CURRENT session actually has
id
# Is the user listed in the docker group on disk?
getent group docker
# Confirm the daemon is up (rules out "cannot connect")
systemctl is-active docker$ ls -l /var/run/docker.sock
srw-rw---- 1 root docker 0 Jun 27 05:00 /var/run/docker.sock
$ id
uid=1001(deploy) gid=1001(deploy) groups=1001(deploy) # no "docker" -> denied
$ getent group docker
docker:x:998:deploy # user is in the group on disk, but session is stale
-
Add the user to the
dockergroup:sudo usermod -aG docker "$USER" -
Apply the new group in this session without a full logout:
newgrp docker # or log out and back in / restart the service -
For a systemd service, set
Group=docker(orSupplementaryGroups=docker) in the unit andsystemctl daemon-reload && systemctl restart <svc>. -
If you must avoid granting host-root via the socket, run Docker in rootless mode instead of broadening socket access.
id | grep -o docker # docker now appears in groups
docker ps # lists containers with no permission error- Bake
dockergroup membership into host/runner provisioning (cloud-init, AMI). - Treat
dockergroup membership as root-equivalent in your access reviews. - Prefer rootless Docker for untrusted or shared multi-tenant hosts.
docker · socket · permissions · security · production