Docker permission denied: why it happens and how to fix it properly
Description and use
Users learn to distinguish socket versus file permission errors, apply group membership, ownership alignment, or SELinux relabeling, and avoid insecure workarounds like chmod 777.
Problem
Users encounter "permission denied" errors when running Docker commands or inside containers, mistakenly assuming Docker is broken.
Outcome
Users learn to distinguish socket versus file permission errors, apply group membership, ownership alignment, or SELinux relabeling, and avoid insecure workarounds like chmod 777.
Workflow
- Identify error type by reading full message
- If socket error, check /var/run/docker.sock ownership and user groups
- Add user to docker group and re-login or run newgrp docker
- If file error, check host path ownership with ls -ln and container user with docker compose exec app id
- Align UID/GID by chowning host directory or setting user: in compose
- If SELinux enforcing, add :Z or :z volume suffix or disable enforcement temporarily
- Avoid chmod 777; instead correct ownership and permissions
- Verify resolution by re-running Docker command or container operation
Evidence
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
Permission denied or EACCES in container logs
ls -l /var/run/docker.sock
srw-rw---- 1 root docker 0 Oct 7 09:12 /var/run/docker.sock
id -nG
hitesh adm sudo <- no "docker" here, that is the problem
ls -ln /srv/app
drwxr-xr-x 2 0 0 4096 Oct 7 10:02 data
docker compose exec app id
uid=1000(node) gid=1000(node)
ls -ldZ /srv/app/data
drwxr-xr-x. 2 1000 1000 unconfined_u:object_r:var_t:s0 6 Oct 7 11:40 /srv/app/data
- Record date: 2026-10-07T04:41:04.794Z