I m trying to run docker with Jenkins pipeline but I m facing this Jenkins pipeline error and a socket io error

0 votes

I’m trying to execute a docker image within a Jenkins pipeline but I always come across this error. Any help?

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.26/containers/hello-world/json: dial unix /var/run/docker.sock: connect: permission denied.

Jun 26, 2018 in Docker by Zulaikha
• 910 points
46,282 views

4 answers to this question.

+2 votes
Best answer

This happens when the Jenkins user is not added to the docker group. So first try to create a Jenkins user and add the user to the docker group. Follow the below steps:

1. Create a docker group if you haven’t done it already. 

$ sudo groupadd docker

2. Create a Jenkins user and add it to the docker group.

$ sudo usermod -aG docker $USER

3. Log off, restart your Jenkins and try executing the program. If you’re still getting the same error then change the access permission of the /var/run/docker.sock  by using the following command.

$ chmod 777 /var/run/docker.sock

Ready to level up your Docker skills? Enroll now in our comprehensive Docker Course!

answered Jun 26, 2018 by Sophie may
• 10,620 points

selected Oct 9, 2019 by Kalgi
Thank you Man
I was struggling immensely on this part..this is what made my day...huge huge thanks

Btw

chmod 777

is the worst security practice ever. The suffice should be to add the jenkins user to docker group and do a service restart of jenkins.
I totally agree with you @Jai. I think it should only be used in the worst-case scenario.
1. After adding jenkins user to docker group,

2. RUN -> newgrp docker

3. Restart the jenkins
Thank you so much vignesh.

RUN -> newgrp docker

This saved my day!
this is save my time too, Thank you for your comment
0 votes
Add Jenkins user to Docker group.
answered Apr 23, 2019 by Vismaya
0 votes

Change the permissions of the file:

$ chmod 777 /var/run/docker.sock
answered Apr 23, 2019 by Anusha
Thanks! That worked for me! :)
Thanks that worked for me...... Very useful.........
thank you so much you saved me
thank you ,so much..this really worked
Thank you for your contribution. Please upvote the answer in case you found it helpful.

Cheers!
"chmod 777 /var/run/docker.sock" is working only one time. The next time I start and stop my EC2 instance, the job fails with error "dial unix /var/run/docker.sock: connect: permission denied".
I have already performed: "sudo groupadd docker" & "sudo usermod -aG docker $USER"
The issue still persists. Do you have any other suggestions?
Did you mount this folder with your container?
+1 vote
bash into container as root user - docker exec -it --user root <dc5> bash

add user to docker group - usermod -aG docker jenkins

change permissions - chmod 777 /var/run/docker.sock
answered May 10, 2020 by Nitin
• 160 points

Related Questions In Docker

0 votes
1 answer

Error while trying to run an image - Docker

This error means that the container tries ...READ MORE

answered Aug 22, 2018 in Docker by Nilesh
• 7,060 points
12,331 views
0 votes
1 answer

How to create a container and run images in docker?

Look for what all images you have ...READ MORE

answered Feb 23, 2019 in Docker by Kalgi
• 52,350 points
2,224 views
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,020 points
2,719 views
0 votes
1 answer

How to run a docker command from inside the container?

You must have come across the /var/run/docker.sock file, ...READ MORE

answered Jun 28, 2018 in Docker by Sophie may
• 10,620 points
3,521 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP