Docker
Permission Denied Issue
Troubleshooting
Tech Support
Software Fixes

How to fix Docker, Got permission denied issue

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

When working with Docker, encountering a "permission denied" error can be frustrating. This error typically means that your Docker client isn't allowed to access the Docker daemon due to insufficient permissions. This article provides a comprehensive look at why this happens and how you can fix it.

Understanding Docker’s Permission Denied Issue

Docker operates using a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and managing Docker containers. The error usually occurs when the Docker client does not have permission to communicate with the Docker daemon.

This issue frequently arises under these scenarios:

  1. User not in the Docker Group: The Docker daemon can run as a Unix socket which is owned by root:docker. If your user is not part of the docker group, you're likely to face permission issues.
  2. Misconfigured Docker Daemon: Sometimes, the Docker daemon may be configured to listen on a TCP socket without proper ACLs, making access problematic.
  3. Running Docker without Sudo: On most installations, Docker requires sudo to function correctly unless a user is added to the Docker group.

Steps to Fix the Permission Denied Issue in Docker

1. Adding your user to the Docker group

You can add your user to the Docker group with the following command:

bash
sudo usermod -aG docker $USER

Note: After running this command, you must log out and back in for the group changes to take effect.

2. Check if Docker Daemon is running

Ensure that the Docker daemon is running using:

bash
sudo systemctl status docker

If it's not running, start it:

bash
sudo systemctl start docker

3. Adjusting Docker Daemon configuration

If Docker is configured to use a TCP socket (for example, for remote access), verify that your configuration appropriately secures the socket with SSL and firewall rules. Alternatively, reconfigure Docker to use Unix socket with appropriate user/group ownership.

4. Using Docker without Sudo

If you prefer not to use sudo every time you run Docker, ensure your user is added to the Docker group as described above. If permission issues persist, restart the Docker service to ensure all configurations are reloaded and applied:

bash
sudo systemctl restart docker

5. Verify Permissions on Docker Socket

The Docker socket (/var/run/docker.sock) should typically own by root in the docker group. Check permissions using:

bash
ls -l /var/run/docker.sock

The output should be similar to:

 
srw-rw---- 1 root docker 0 Mar  10 12:00 /var/run/docker.sock

If the group is incorrect, correct it using:

bash
sudo chown root:docker /var/run/docker.sock

Summary Table

Issue PotentialCommand or CheckPurpose/Outcome
User not in Docker groupsudo usermod -aG docker $USERAdds user to Docker group to avoid using sudo
Docker daemon not runningsudo systemctl status/start dockerEnsures Docker daemon is running
Misconfiguration in TCP socketVerify /etc/docker/daemon.json settingsEnsures Docker daemon uses secure connections
Permissions on Docker socketls -l /var/run/docker.sockChecks if Docker socket has correct permissions

Troubleshooting Tips

  • After making changes to user groups or daemon configuration, rebooting your system may be helpful to ensure changes take effect system-wide.
  • Ensure SELinux (Security-Enhanced Linux) or other security modules are not interfering with Docker operations.
  • Always pull the latest version of Docker and its dependencies to avoid bugs that might be causing permission issues.

Addressing the "permission denied" issue in Docker involves ensuring proper user permissions, correctly configuring the Docker daemon, and verifying that Docker's socket file has the correct ownership. Following the steps outlined above should help resolve most instances of this problem.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.