Permission Denied
Error message
permission denied while trying to connect to the Docker daemon socket
Quick summary
The current user lacks the necessary permissions to execute a command or access a resource.
Why this happens
The user is not in the docker group and cannot access the Docker daemon
A container user does not have write permission to a mounted volume
Kubernetes RBAC rules deny the service account access to a resource
File permissions on the host prevent the container from reading or writing
Minimal example
$ docker ps
Got permission denied while trying to connect to the Docker daemon socket$ sudo usermod -aG docker $USER
$ newgrp docker
$ docker ps # now worksThe user is not in the docker group. The fix adds the user to the group and refreshes the group membership.
How to diagnose
Check the error message for the specific resource being denied
Verify the user running the command and their group membership
In Kubernetes, check RBAC roles and bindings with
kubectl auth can-iCheck file permissions on the host:
ls -la /path/to/file
How to fix
Add the user to the docker group:
sudo usermod -aG docker $USER(then re-login)Fix file permissions:
chmodorchownthe file or directoryCreate or update RBAC Role/RoleBinding to grant the required permissions
Set the correct user in the Dockerfile with
USERdirective
How to prevent
Set up proper RBAC roles for service accounts from the start
Use least-privilege users in containers
Document required permissions for each service