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
The Jenkins project provides Docker images for controllers, inbound agents, outbound agents, and more.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With