Is there any command which we can run and find out the "Docker Host URI"? I found some of related questions but didn't get it exactly.
5 Answers
Jenkins Docker Plugin Configuration when running jenkins as container
First Install Docker Plugin.
Go to Manage Jenkins -> System Configuration -> Scroll down to botton -> Add Cloud -> Docker.
If you are running jenkins as container, in the docker host uri field you have to enter unix or tcp address of the docker host. But since you are running jenkins as container, the container can't reach docker host unix port.
So, we have to run another container that can mediate between docker host and jenkins container. It will public docker host's unix port as its tcp port. Follow the instructions to create socat container https://hub.docker.com/r/alpine/socat/
After creating the socat container, you can go back the docker configuration in jenkins and enter tcp://socat-container-ip:2375
Test Connection should succeed now.
-
2This is the correct answer for people using **Docker for MacOS** and running **Jenkins in a container**. After days of research, @shaik47 answer was what worked for me. MacOS Mojave: 10.14.5, Docker for MacOS: 2.1, Engine: 19.03 – Stevens Garcia Aug 07 '19 at 18:29
-
Thanks @shaik47 it works for me. My configuration is MacOS Mojava: 10.14.6 Docker Engine 19.03.5 – Rakesh Kasinathan May 07 '20 at 16:11
-
1Above solution works well for AWS Cent OS as well where Jenkins container tries to configure Docker hub. Used below two commands to find ip address of socat container. Thank you very much..... docker ps docker inspect container_name | grep IPAddress – Ashutosh Shukla Aug 21 '20 at 17:39
-
@Shaik47 : do i need to provide any connection between socat and Jenkins as i followed step#4 and #5 but still failing with CONNECTION REFUSED error.Please help if you have pointers... – Krishh Jan 07 '21 at 14:46
The other option would be to enter Docker Host URI "unix: ///var/run/docker.sock", it worked for me, I hope that it is also.

- 395
- 4
- 15
-
2It works perfectly without any other change on the system. Thanks! – Chrístopher Ávila Holguín Jan 14 '20 at 10:57
-
6I had to remove a space between `unix:` and `///var`. Other than that, it works! – SantaXL May 28 '20 at 22:53
-
On Mac - jenkins - Error: java.io.IOException: com.sun.jna.LastErrorException: [2] No such file or directory – MPV Aug 30 '23 at 23:19
Yes this is the docker host uri
tcp://127.0.0.1:2375
But before that you need to add this DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock"
In /etc/default/docker
at the end of file, then restart the docker.onec restarted docker.sock will run in 2375 and add this tcp://127.0.0.1:2375 in Jenkins

- 7,684
- 3
- 29
- 49

- 5,179
- 1
- 21
- 30
-
1Additionally to change DOCKER_OPTS you probably should check what is your docker host IP address is, check this out https://stackoverflow.com/questions/22944631/how-to-get-the-ip-address-of-the-docker-host-from-inside-a-docker-container Then you should put this IP along with the port specified in DOCKER_OPTS into 'Manage Jenkins/Configure System/Docker Host URI'. Suppose IP is 172.17.0.1 and port is 2375, then Docker Host URI would be: `tcp://172.17.0.1:2375` – klapshin Jan 16 '19 at 18:17
-
-
If you enter this in your Jenkins agent config, you'll be creating agent containers inside your Jenkins host. If you run docker on the Jenkins host and this is what you want to do, then you can use the loopback address (127.0.0.1). Otherwise, for example if you run Jenkins in a container and you want the agents to be in separate containers, you need another answer. See the answer from @shaik47. – Jeter-work Apr 04 '23 at 23:08
If your docker running at the same host were you use Jenkins inside a container than you can use unix:///var/run/docker.sock as the “Docker Host URI”, but you must check & obtain the permissions for jenkins user by using:
sudo groupadd docker
sudo usermod -aG docker $USER
sudo chmod a+rwx /var/run/docker.sock
sudo chmod a+rwx /var/run/docker.pid

- 51
- 3