permission denied while trying to connect to the Docker daemon socket
The socket exists and the kernel refused the connection. Group membership, stale login shells, rootless paths and SELinux are the real causes.

Introduction & Quick Summary
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/version":
dial unix /var/run/docker.sock: connect: permission deniedThe client reached the socket file and the kernel refused the connection because your user lacks permission on that inode. This is an operating-system permission problem, not a Docker problem: the daemon is running, the socket exists, and the CLI is fine.
Four things to check, in order:
- You are not in the
dockergroup. The socket is usuallysrw-rw---- root docker, so membership is the intended access path. - Your shell has not picked up the new group.
usermod -aG docker $USERaffects future logins only; the current session still carries the old group list. - The socket lives somewhere else. Rootless Docker uses
$XDG_RUNTIME_DIR/docker.sock, Colima and Rancher Desktop use a per-user path, and a strayDOCKER_HOSTpoints the client at the wrong file. - Mandatory access control is blocking it. SELinux or AppArmor can deny access even with correct group membership, and on some hosts the socket context was changed by a manual
chmod.
| Symptom | Distinguishing test | Fix |
|---|---|---|
| Fails as user, works as root | sudo docker version succeeds | Join docker group, re-login |
| Group listed but still denied | id -nG lacks docker | Start a new login shell |
dial unix ...: no such file | Path wrong, not permission | Check docker context ls |
| Works in IDE, fails in terminal | Different shells load different env | Check DOCKER_HOST per shell |
| Works until reboot | Rootless socket path changes | Export DOCKER_HOST in profile |
Core Mechanics, Signatures & Reproducible Setup
The daemon listens on a Unix socket owned by root:docker with mode 0660 by default. Unix socket permissions are enforced by the kernel at connect(), so group membership is what grants access. Socket activation through systemd keeps the socket at /run/docker.sock (a symlink target of /var/run/docker.sock), and its ownership is re-applied on each start.
Inspect the actual state rather than trusting a guide:
ls -l /var/run/docker.sock
stat -c '%U:%G %a %n' /var/run/docker.sock
id -nG
getent group docker
docker context ls
echo "DOCKER_HOST=$DOCKER_HOST"A correct, minimal setup on a Debian-like host:
sudo groupadd -f docker
sudo usermod -aG docker "$USER"
newgrp docker # applies to this shell only
docker run --rm hello-worldnewgrp docker opens a subshell with the new group so you do not have to log out; a full re-login is still required for IDE terminals, tmux servers and SSH sessions started before the change.
For the rootless case the socket is not in /var/run at all:
export DOCKER_HOST="unix://$XDG_RUNTIME_DIR/docker.sock"
docker context use rootless
docker info --format '{{.SecurityOptions}}'A quick reproduction of the exact failure uses a fresh user with no supplementary groups:
sudo useradd -m tester
sudo -u tester docker ps
# permission denied while trying to connect to the Docker daemon socket
sudo usermod -aG docker tester
sudo -u tester -i docker ps # still cached? use a login shellKey Comparison Table
| Access model | Socket path | Owner:group | Survives reboot |
|---|---|---|---|
| Rootful, systemd socket | /var/run/docker.sock | root:docker | Yes, recreated with same mode |
Rootful, manual dockerd | /var/run/docker.sock | Set at start | Depends on unit file |
| Rootless | $XDG_RUNTIME_DIR/docker.sock | Your user | Path changes per session |
| Docker Desktop Linux | ~/.docker/desktop/docker.sock | Your user | Yes |
| Colima | ~/.colima/default/docker.sock | Your user | Per profile |
| Remote TCP with TLS | tcp://host:2376 | n/a | Requires certs |
| Fix | Scope | Security effect | Persistence |
|---|---|---|---|
Add user to docker group | Whole user account | Equivalent to root on the host | Permanent |
sudo docker | Single command | Runs the client as root | None |
chmod 666 the socket | All local users | Removes access control | Until daemon restart |
| Rootless Docker | Your user only | Smallest blast radius | Per session or linger |
DOCKER_HOST to a VM | Single project | Isolated daemon | Wherever exported |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
Case 1: CI runners that recreate the user every job
A containerized CI job usually already runs as root; a self-hosted runner does not. Add the group in the runner's shell profile rather than in the pipeline, and remember that the docker group must exist before usermod runs:
sudo groupadd -f docker
sudo usermod -aG docker "$(id -un)"
exec sudo -u "$(id -un)" -i bash -lc 'docker info >/dev/null'Case 2: IDE and GUI sessions with stale groups
VS Code, JetBrains IDEs and desktop launchers inherit the group list from the session manager at login. After changing membership, log out of the desktop session, not just the terminal. Verify from inside the IDE's integrated terminal with id -nG.
Case 3: The socket exists but the daemon is not running
sudo systemctl status docker.socket docker.service
journalctl -u docker.service -n 50 --no-pagerA stopped daemon yields connect: no such file or directory on some hosts and this permission error on others when systemd socket activation holds a stale path. Restart the socket unit first, then the service.
Case 4: Podman's Docker compatibility socket
podman.socket provides /run/user/$UID/podman/podman.sock, and symlinking it to /var/run/docker.sock is a common shortcut that produces confusing permission errors later. Point the client explicitly instead:
export DOCKER_HOST="unix:///run/user/$(id -u)/podman/podman.sock"
docker context create podman --docker "host=$DOCKER_HOST"
docker context use podmanCase 5: SELinux denials on Fedora and RHEL
sudo ausearch -m avc -ts recent | grep docker
ls -Z /var/run/docker.sockIf the context is not docker_var_run_t or an equivalent, restore labeling rather than widening permissions:
sudo restorecon -v /var/run/docker.sockCase 6: Testcontainers and language SDKs
Libraries read the environment, not your shell history. A test that fails in Maven or Gradle but passes with docker run is usually reading a different socket. Configure it explicitly:
DockerClientFactory.instance().client(); // Testcontainers
// or
// TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/run/user/1000/docker.sockCommon Compilation/Runtime Mistakes & Version Gotchas
sudo dockercreates root-owned files. Containers mounting a bind volume write files as root, and the next non-root build fails on permission. Use--user $(id -u):$(id -g)or fix ownership after the fact.- The
dockergroup is root-equivalent. Anyone in it can mount the host filesystem into a container. On shared machines, rootless Docker or a remote builder is the safer arrangement. chmod 666is not a fix. It survives only until the daemon restarts and silently grants every local process full control of the host.- Docker Desktop on Linux. It uses its own socket under
~/.docker/desktop/and a context nameddesktop-linux, so host instructions aboutsystemctl enable dockerdo not apply andusermodchanges nothing. - WSL2. The distribution needs Docker integration enabled in Docker Desktop settings; group membership inside WSL is irrelevant because the socket is a Windows-side proxy.
- Socket path length in
DOCKER_HOST.unix://plus a long home path can exceed the 108-bytesun_pathlimit and produce an error that reads like a permission failure.
When the error is wrapped inside a long stack trace from a build tool, extract the daemon response and inspect it with the JSON formatter if the API returned structured output; docker info --format '{{json .SecurityOptions}}' is a quick way to confirm whether a rootless or SELinux profile is active. If you need to reproduce the daemon call by hand, the curl generator can build the --unix-socket request. For checking the port and socket path a Compose file expects, the Docker Compose viewer validates the file before a docker compose up fails for an unrelated reason.
Primary references: Docker's post-install steps for Linux cover group membership and its security implications, and rootless mode documents the socket path and setup for non-root daemons.
Official references
primary documentationThe Docker documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Docker work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Docker guides
All Docker guidesDocker build: failed to compute cache key: not found
BuildKit cannot hash a file that is not in the context. Correct the context path, the .dockerignore rules, or the COPY source and stage name.
Docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock
An endpoint mismatch, a stopped daemon, or a missing socket mount. Resolve which of the three, then start, retarget, or mount.
Docker Compose: bind: address already in use and Port Conflicts
A published port is a host socket, and two projects cannot own it. How to find the real owner, why an override file merged instead of replacing, and how.
Docker Buildx: Building Multi-Architecture Images (AMD64 & ARM64) Explained
One tag, several architectures: the driver that supports it, QEMU versus cross-compilation, registry cache, and reading the manifest list.
More in Docker
All Docker guidesThe guides filed next to this one in Docker, in library order.