Docker jenkins & docker agent jenkins

Hi,
I use the docker jenkins Version 2.429.

I want to configure My jenkins to use a docker agent.
I configure like this :

Docker

  • Host URI = unix:///var/run/docker.sock
  • Docker API Version = 1.43
  • Docker Hostname or IP address = “Ip of my linux serveur on witch my jenkins conteneur run”

When I test that connection, I have :

org.apache.hc.client5.http.HttpHostConnectException: Connect to unix://localhost:2375 [localhost/127.0.0.1] failed: Connection refused

Can someone help me ?

Thx
Michel

If you are testing with just localhost, then it bypasses your choice of unix:///var/run/docker.sock. You need to test with that host rather than localhost.

Hi,
I don’t understand why with

unix:///var/run/docker.sock

I have

Connect to unix://localhost:2375

I change it by

tcp://172.xxx.xxx.xxx:2375 (the IP serveur where my container runs)

and I obtain

org.apache.hc.client5.http.HttpHostConnectException: Connect to http://172.xxx.xxx.xxx:2375 [/172.xxx.xxx.xxx] failed: Connection refused

I read that :

  • 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 Docker
  • 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.

is it the only solution ?

thanks

you don’t get to make up host names… unix://localhost:2375 is not a valid host name

tcp://localhost:2375 is valid for connecting to port 2375 over TCP. You have to configure dockerd to listen on this port first.
unix://var/run/docker.sock is valid for connecting using a socket file directly on your local machine. This is always configured.