Skip to content

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

✗ Broken code
$ docker ps
Got permission denied while trying to connect to the Docker daemon socket
✓ Fixed code
$ sudo usermod -aG docker $USER
$ newgrp docker
$ docker ps  # now works

The 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-i

  • Check 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: chmod or chown the file or directory

  • Create or update RBAC Role/RoleBinding to grant the required permissions

  • Set the correct user in the Dockerfile with USER directive

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

Related Resources

Related Glossary

← Back to language