Docker
troubleshooting
permission issues
Linux
error resolution

How to fix Docker Permission denied

System Design practice on Codemia

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

Practice system design

Introduction

A Docker "permission denied" error usually means the Docker client cannot reach the daemon through its Unix socket. On Linux, that socket is commonly /var/run/docker.sock, and access to it is controlled by the operating system rather than by Docker commands alone. The fix is usually simple, but only after you identify whether the problem is the daemon, the socket permissions, the current user session, or the environment you are actually targeting.

Start by Identifying the Real Failure

A common error looks like this:

text
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

That message usually points to one of four cases:

  • the Docker daemon is not running
  • your user is not allowed to access the socket
  • the socket ownership or group is wrong
  • you are using a shell or Docker context that is not the one you think it is

Check the daemon first:

bash
sudo systemctl status docker
sudo systemctl start docker

If the daemon is not running, fixing group membership will not help.

The Usual Fix on Linux: Join the docker Group

On a standard Linux install, non-root access to Docker is typically granted through the docker group.

bash
sudo usermod -aG docker "$USER"
newgrp docker
docker run hello-world

newgrp docker starts a shell with the updated group membership. If you prefer, you can also log out and back in. Until you start a fresh session, the old shell may not see the new group.

Check your active groups with:

bash
id

If docker is not listed yet, you are still testing from the old session state.

Inspect the Socket Itself

If your user is in the correct group but the error remains, inspect the socket:

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

On a healthy setup, you often see ownership similar to root docker with permissions like rw-rw----. If the socket group is wrong, restarting the daemon often recreates it correctly:

bash
sudo systemctl restart docker

Avoid the tempting shortcut:

bash
sudo chmod 666 /var/run/docker.sock

That opens the daemon socket to all local users, weakens security, and often gets undone the next time Docker restarts anyway.

Know When sudo docker ... Is Only a Workaround

Running Docker with sudo can confirm that the daemon itself works:

bash
sudo docker ps

If that succeeds while plain docker ps fails, the daemon is reachable and the problem is your user access path.

This is useful as a diagnostic step, but it is not a great long-term habit. Mixing sudo and non-sudo Docker commands can create root-owned files inside bind mounts and project directories, which then causes application-level permission problems later.

Check for Environment Mismatch

Not every "permission denied" message is about a local Linux socket.

Verify:

  • whether you are on Linux versus Docker Desktop
  • whether you are inside WSL
  • whether docker context ls points to a remote daemon
  • whether a CI runner actually exposes Docker to the job

For example:

bash
docker context ls
docker context use default

If the active context points to another host, you may be debugging the wrong machine entirely.

Consider Rootless Docker if That Matches Your Security Model

If you do not want ordinary users to access a root-owned daemon through the docker group, look at Docker rootless mode. That is a different setup, so it is not the first fix for a normal workstation, but it is worth knowing that "add the user to the docker group" is not the only model Docker supports.

The important tradeoff is that membership in the docker group is powerful. In practical terms, it gives a user very broad control over the host. Treat it as privileged access, not as a harmless convenience flag.

A Good Debugging Sequence

When the error appears, debug in this order:

  1. confirm the daemon is running
  2. confirm your current shell session belongs to the docker group
  3. inspect the socket owner and group
  4. verify the active Docker context
  5. only then consider environment-specific cases such as WSL or CI

That order is efficient because it eliminates the common cases first.

Common Pitfalls

One common mistake is adding the user to the docker group and immediately retrying from the same shell session. The group change has not taken effect yet, so it looks like the fix did nothing.

Another mistake is using chmod 666 on the Docker socket. That bypasses the real access model and weakens the machine's security.

Developers also sometimes forget to check whether the daemon is actually running. A stopped daemon and a permission problem can look similar when you only skim the first line of the error.

Finally, do not ignore Docker contexts. If the client is pointed at another host, local socket fixes can waste a lot of time.

Summary

  • Docker permission errors usually mean the client cannot access the daemon socket.
  • Start by confirming the Docker service is running.
  • On Linux, the standard non-root fix is to add the user to the docker group.
  • Inspect /var/run/docker.sock instead of opening it to everyone with broad permissions.
  • Treat Docker access as privileged, and check the active Docker context before assuming the problem is local.

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.