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

Quickest way to fix How to fix “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/auth”: dial unix /var/run/docker.sock: connect: permission denied” error.

How to fix permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: error

Error:

Received error during login to Docker from Ubuntu 20.04 running on WSL.

blackmoreops@wsl:/home$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: blackmoreops
Password:
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/auth": dial unix /var/run/docker.sock: connect: permission denied

Short version:

Fix:

This is a quick way to fix it, just opened  a terminal and typed this command to fix permission error. (user already had sudo access)

sudo chmod 666 /var/run/docker.sock

Verify:

Always verify,

blackmoreops@wsl:/var/run$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: blackmoreops
Password:
WARNING! Your password will be stored unencrypted in /home/blackmoreops/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

Long version:

According to the official Docker docs here:

You need to do the following:

To create the docker group and add your user:

Create the docker group

sudo groupadd docker

Add your user to the docker group

sudo usermod -aG docker ${USER}

Relogin

You would need to logout and log back in so that your group membership is re-evaluated or type the following command:

su -s ${USER}

Verify

Verify that you can run docker commands without sudo.

docker run hello-world
  • This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

Fixing WARNING: Error loading config file error

If you initially ran Docker CLI commands using sudo before adding your user to the docker group, you may see the following error, which indicates that your ~/.docker/ directory was created with incorrect permissions due to the sudo commands.

WARNING: Error loading config file: /home/user/.docker/config.json -stat /home/user/.docker/config.json: permission denied

To fix this problem, either remove the ~/.docker/ directory (it is recreated automatically, but any custom settings are lost), or change its ownership and permissions using the following commands:

sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R

 

Your call which one is more suitable for you. I was running it on WSL for testing, so picked the quick and dirty one. If I was to do it in a serious environment, I’d probably go with the long version.

That’s it.

Check Also

Whispers: A Powerful Static Code Analysis Tool for Credential Detection

“My little birds are everywhere, even in the North, they whisper to me the strangest …

How to fix You can’t access this shared folder because your organization’s security policies block unauthenticated guest access error on Windows 11

If you have the following error on Windows 11 “You can’t access this shared folder …

Leave your solution or comment to help others.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from blackMORE Ops

Subscribe now to keep reading and get access to the full archive.

Continue reading

Privacy Policy on Cookies Usage

Some services used in this site uses cookies to tailor user experience or to show ads.