docker.sock permission denied
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Docker has become an essential tool in modern application development and deployment. It allows developers to create lightweight, portable, and self-sufficient containers that run in any environment. However, one common issue developers encounter is the "docker.sock permission denied" error. This error can cause significant roadblocks if not understood and resolved effectively. This article delves into the technical aspects of this issue, offers solutions, and enhances your understanding of Docker's security mechanisms.
Understanding docker.sock
The `docker.sock` file is a Unix domain socket that facilitates communication between the Docker client and the Docker daemon. This socket file is usually located at `/var/run/docker.sock`. Its primary purpose is to allow processes and users to send Docker commands to the Docker daemon.
Why Permission Denied?
The error "docker.sock: permission denied" typically occurs when the user attempting to access the Docker socket doesn't have the necessary permissions. This restriction is in place because accessing the Docker socket provides a significant degree of control over the Docker daemon, thereby affecting the entire host system. Only trusted users with administrative privileges should have access.
Common Scenarios for "Permission Denied"
- User Not in Docker Group: The most common scenario is that the user is not part of the Docker group. Docker demon runs with root privileges, and access to `docker.sock` is controlled through group permissions.
- SELinux or AppArmor Restrictions: Security-enhanced Linux (SELinux) and AppArmor may have restrictions that prevent access to Docker's socket.
- Incorrect File Permissions: The permissions for the socket file `/var/run/docker.sock` might not allow the current user to read/write to it.
- Daemon Misconfiguration: The Docker daemon may be misconfigured, or it might not be running, leading to permission issues as a secondary effect.
Solving the Permission Denied Issue
Adding User to Docker Group
The quickest solution is by adding the user to the Docker group. You can achieve this as follows:
Related reading
- Does Alpine have known DNS issue within Kubernetes?
- Does Kubernetes cache docker-registry secrets?
- Does kubernetes have its own Load Balancer?
- domain configuration in docker-compose
- Doctrine - How to print out the real sql, not just the prepared statement?
- Does a finally block run even if you throw a new Exception?
- Dropping container with RabbitMQ in Docker
- Dynamically get a running container id/name created by docker run command

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.