18

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.

Anand
  • 2,239
  • 4
  • 32
  • 48

5 Answers5

27

Jenkins Docker Plugin Configuration when running jenkins as container

  1. First Install Docker Plugin.

  2. Go to Manage Jenkins -> System Configuration -> Scroll down to botton -> Add Cloud -> Docker.

  3. 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.

  4. 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/

  5. After creating the socat container, you can go back the docker configuration in jenkins and enter tcp://socat-container-ip:2375

  6. Test Connection should succeed now.

Bip Lob
  • 485
  • 2
  • 6
  • 15
shaik47
  • 393
  • 1
  • 3
  • 5
  • 2
    This 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
  • 1
    Above 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
15

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.

Bastián SN
  • 395
  • 4
  • 15
12

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

Tai
  • 7,684
  • 3
  • 29
  • 49
sanath meti
  • 5,179
  • 1
  • 21
  • 30
  • 1
    Additionally 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
  • how to do this in docker for windowsCE ? – Vikash Jun 14 '19 at 07:30
  • 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
4

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
1

If you are in the OS X, the HOST URL is:

unix:///var/run/docker.sock
Arefe
  • 11,321
  • 18
  • 114
  • 168