8

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Amir-Mousavi
  • 4,273
  • 12
  • 70
  • 123
  • Did you try opening new shell? It might be that group membership doesn't apply to your current shell. – Igor Nikolaev Feb 04 '19 at 21:24
  • @IgorNikolaev I doubt what you mean by opening a new shell? doesn't the rebooting system count as if a new shell is opened? – Amir-Mousavi Feb 04 '19 at 21:48
  • 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 (https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04) and it worked after that. – Igor Nikolaev Feb 05 '19 at 20:59
  • 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. – Igor Nikolaev Feb 05 '19 at 21:00
  • Is this a dupe to https://stackoverflow.com/questions/42164653/? – Simón Mar 25 '20 at 04:39

1 Answers1

9

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Adarsha Jha
  • 1,782
  • 2
  • 15
  • 37