Back to Guides

How to fix Docker Permission Denied

May 20, 2024
2 min read
DockerLinuxTroubleshooting

How to Fix Docker Permission Denied Errors

If you're getting permission denied errors when running Docker commands, it's likely because your user isn't in the docker group.

The Problem

When you install Docker, it creates a Unix socket that only the root user and users in the docker group can access. If your user isn't in this group, you'll see errors like:

docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied.

The Solution

Add your user to the docker group:

sudo usermod -aG docker $USER

Important Security Note

⚠️ Warning: Adding a user to the docker group is equivalent to giving them root access. Only do this on trusted systems.

Apply the Changes

After running the command, you'll need to log out and back in for the group membership to take effect. Alternatively, you can run:

newgrp docker

Verify It Works

Test with a simple command:

docker run hello-world

If it works, you're all set!

Troubleshooting

If you're still having issues:

  1. Make sure Docker is running: sudo systemctl start docker
  2. Check your group membership: groups $USER
  3. Restart your session completely

Alternative: Use sudo

If you don't want to add your user to the docker group, you can prefix all docker commands with sudo:

sudo docker run hello-world

But this gets tedious quickly.