Docker: Got permission denied while trying to connect to the Docker daemon socket
Asked Answered
M

1

9

On the Ubuntu 18.04 (Bionic Beaver) system, I have cloned a project and to run it needs Gradle, but at running the Gradle command gradle swiplRun I get the following error

Task :dockerRun FAILED 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.39/containers/create?name=swiprolog: dial unix /var/run/docker.sock: connect: permission denied. See 'docker run --help'.

Task :dockerRunStatus FAILED Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/swiprolog/json: dial unix /var/run/docker.sock: connect: permission denied

FAILURE: Build completed with 2 failures.

To solve it, I tried:

sudo groupadd docker
sudo usermod -a -G docker myname
  "and once with"
sudo gpasswd -a myname docker

So I can run Docker commands without sudo, but the same error. Also ./gradlew --stop and logout/login and reboot did not work either.

Is it because of Docker or Gradle?

Midgard answered 4/2, 2019 at 20:39 Comment(5)
Did you try opening new shell? It might be that group membership doesn't apply to your current shell.Seigniorage
@IgorNikolaev I doubt what you mean by opening a new shell? doesn't the rebooting system count as if a new shell is opened?Midgard
Rebooting should help, I must have missed that you tried to login/logoff. How did you install Docker? I remember installing Docker recently on Ubuntu and it required custom package repository to be added. I think we followed this instruction (digitalocean.com/community/tutorials/…) and it worked after that.Seigniorage
Also probably verify that your user had docker group assigned after all. It didn't work for us for some reason at first, only after we installed Docker according to the documentation mentioned above.Seigniorage
Is this a dupe to stackoverflow.com/questions/42164653?Alyss
G
13

Try restarting Docker once:

sudo systemctl restart docker

Then this one to finally solve the problem:

sudo chmod 666 /var/run/docker.sock

Now try running:

docker run hello-world

It will pull the image from the Docker Hub repository and that means your Docker instance is now running properly.

Goldoni answered 17/7, 2020 at 13:15 Comment(3)
This didn't work for me. Something is resetting my permissions.Stilwell
can you try reinstalling docker ? and then follow this ? @KirkSefchikGoldoni
worked on Ubuntu WSL2Schelling

© 2022 - 2024 — McMap. All rights reserved.