Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am new to docker. I just tried to use docker in my local machine(Ubuntu 16.04) with Jenkins.

I configured a new job with below pipeline script.

node {     stage('Build') {       docker.image('maven:3.3.3').inside {         sh 'mvn --version'       }     } } 

But it fails with below error.

enter image description here

like image 403
Ponsuyambu Avatar asked Dec 17 '17 11:12

Ponsuyambu


People also ask

How do I fix docker got permission denied while trying to connect to the docker Daemon socket?

Fix 1: Run all the docker commands with sudo If you have sudo access on your system, you may run each docker command with sudo and you won't see this 'Got permission denied while trying to connect to the Docker daemon socket' anymore.

How do I fix permission denied docker?

If running elevated Docker commands does not fix the permission denied error, verify that your Docker Engine is running. Similar to running a docker command without the sudo command, a stopped Docker Engine triggers the permission denied error. How do you fix the error? By restarting your Docker engine.

What permissions should docker sock have?

The Docker socket file should therefore have permissions of 660 or more restrictive permissions.


1 Answers

The user jenkins needs to be added to the group docker:

sudo usermod -a -G docker jenkins 

Then restart Jenkins.

Edit

If you arrive to this question of stack overflow because you receive this message from docker, but you don't use jenkins, most probably the error is the same: your unprivileged user does not belong to the docker group.

You can do:

sudo usermod -a -G docker [user] 

Insert your user name where [user] is.

You can check it was successful by doing grep docker /etc/group and see something like this:

docker:x:998:[user] 

in one of the lines.

Then change your users group ID to docker:

newgrp docker 

Finally, log out and log in again

like image 163
austingray Avatar answered Sep 21 '22 20:09

austingray