How to fix: Docker “Permission Denied”

Every Docker command just returns “Permission Denied”? Don’t panic, this article will show you how to easily fix the Docker Permission Denied error.

You get this or a similar error message? Then you’ve come to the right place!

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get “http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json”: dial unix /var/run/docker.sock: connect: permission denied

Docker Permission Denied Error Message
Docker Permission Denied Error Message

If you get the error message “unable to read config file: open…”, jump directly to the solution.

Docker Permission Denied Error Message: config.json
Docker Permission Denied Fehlermeldung: config.json

Docker Permission Denied

The problem occurs when you have reinstalled or upgraded Docker and try to run the docker command as a non-administrator.

Now, there are several reasons why this error might occur, and several ways to fix it. Simply try the various methods in this article until you get Docker running smoothly (again).

Fix Docker Permission Denied Error

Option 1: Run Docker as administrator

The problem is quickly solved by simply running it as an administrator/root user, i.e. with sudo.

sudo docker run hello-world

In most cases, however, you will want to run the Docker command as the current (non-administrator) user. That’s where option 2 comes in.

Option 2: Adjust permissions for non-root users

If you are using Docker on Linux or in a Linux distribution in WSL2 on Windows, you can adjust the permissions for the Docker socket. To do this, run the following commands (Docker documentation):

# 1. Create docker group
sudo groupadd docker

# 2. Add current user to the docker group
sudo usermod -aG docker $USER

# 3. Reload the group configuration
newgrp docker

Now you should be able to use the docker command without sudo:

docker run hello-world

If this doesn’t work, try option 3.

Option 3: Adapt Docker Socket Permission

It is possible that the permissions on the docker.sock file have been changed and the current user does not have access to it. To adjust the permissions, run the following command:

# Change owner of the docker.sock file
sudo chown root:docker /var/run/docker.sock

Docker Config “Permission Denied”

Are you getting this error message?

WARNING: unable to read config file: open /home/<USER>/.docker/config.json: permission denied
/home/lh/.docker/config.json: open /home/<USER>/.docker/config.json: permission denied

The permissions on the .docker directory in your home directory are incorrect. Use these commands to adjust the permissions.

# 1. Set correct owner for the .docker directory
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R

# 2. Fix the permissions for the .docker directory
sudo chmod g+rwx "$HOME/.docker" -R

That should solve the problem!


With these options, you should be able to solve the Docker Permission Denied problem. Finally, do you know how to use the Docker Init command to automatically create a Dockerfile, .dockerignore and compose.yaml? Learn more: Docker Init Command

Related Posts
Leave a comment

Your email address will not be published. Required fields are marked *

bold italic underline strikeThrough
insertOrderedList insertUnorderedList outdent indent
createLink unlink

This can also interest you