Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins: Can't connect to Docker daemon

I am running Jenkins and Docker on a CentOS machine. I have a Jenkins job that pulls a Github repo and builds a Docker image. When I try running the job I get the error:

+ docker build -t myProject . Cannot connect to the Docker daemon. Is the docker daemon running on this host? Build step 'Execute shell' marked build as failure Finished: FAILURE 

This problem occurs even though I have added jenkins to my docker usergroup via sudo usermod -aG docker jenkins and restarted my machine. How do I fix this?

By the way, if try changing the command to sudo docker build -t myProject . I just get the error sudo: sorry, you must have a tty to run sudo

like image 304
pcsram Avatar asked Jun 29 '16 16:06

pcsram


People also ask

Does Jenkins work with Docker?

The Jenkins project provides Docker images for controllers, inbound agents, outbound agents, and more.


2 Answers

After the installation of Jenkins and Docker. Add jenkins user to dockergroup (like you did)

sudo gpasswd -a jenkins docker 

Edit the following file

vi /usr/lib/systemd/system/docker.service 

And edit this rule to expose the API :

ExecStart=/usr/bin/docker daemon -H unix:// -H tcp://localhost:2375 

Do not create a new line with ExecStart, simply add the commands at the end of the existing line.

Now it's time to reload and restart your Docker daemon

systemctl daemon-reload systemctl restart docker 

Then restart jenkins, you should be able to perform docker commands as jenkins user in your jenkins jobs

sudo service jenkins restart 
like image 59
lvthillo Avatar answered Oct 06 '22 01:10

lvthillo


I had the same issue with Jenkins.

I did fix it by adding /var/run/docker.sock:/var/run/docker.sock on docker-compose.yml :

  jenkins:   container_name: jenkins   build: "jenkins/"   ports:     - "8080:8080"   environment:     - JAVA_OPTS:-Djava.awt.headless=true   volumes:     - /var/jenkins_home     - /var/run/docker.sock:/var/run/docker.sock 
like image 45
S_intg Avatar answered Oct 06 '22 01:10

S_intg