-1

I run a jenkins container but I'd like to Configuring dynamically provisioned Docker agents and I installed docker plugin on jenkins. However I can't reach docker inside the container even if I changed /lib/systemd/system/docker.service turning:

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

into

ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375

and I restart teh daemon with:

sudo systemctl daemon-reload

sudo service docker restart.

After that I went to jenkins configuration and created docker cloud.

the fact is that when I test tcp://172.17.0.1:2375 in docker cloud details it doesn't work. I test in the container ping 172.17.0.1 and the container reaches that host.

Did I miss something?

Salvio
  • 100
  • 2
  • 15
  • What do you mean by `reach docker inside the container`? What your change is just just enable the remote visit of docker engine, didn't see any relationship with your question. – atline Sep 05 '19 at 07:06
  • I meant that if a have a regular installation I can use cloud in jenkins to create docker containers on the fly to use a pipeline. Ho can I do to do the same with a dockerized Jenkins? I can reach docker server on my host environment by using a jenkins container instead of a jenkins regular installation? – Salvio Sep 05 '19 at 07:53

2 Answers2

0

I guess what you need is access docker daemon from docker container:

  1. Add -v /var/run/docker.sock:/var/run/docker.sock when start jenkins container.

  2. Add -v $(which docker):/usr/bin/docker mount to jenkins container, or download related docker prebuilt client from https://download.docker.com/linux/static/stable/, see this.

With 1, the container will be able to connect to docker daemon and new sibling container, with 2, your jenkins container will have docker client available. You may also want to have a look for this.

atline
  • 28,355
  • 16
  • 77
  • 113
  • But in this way I have to launch the container as root because otherwise docker doesn't accept connection on the socket: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json: dial unix /var/run/docker.sock: connect: permission denied – Salvio Sep 05 '19 at 09:19
  • What about add `-u jenkins:$(cut -d: -f3 < <(getent group docker))` when start the jenkins container? – atline Sep 05 '19 at 09:31
  • I launched the container as root but nothing. When I try on my host curl http:// 172.17.0.1:2375/version I get it, but when I try inside the container there is no answer even if I use docker cli it works. How can I reach tpc://172.17.0.1:2375 from the container? – Salvio Sep 05 '19 at 09:43
  • root@3812f8e2aace:/# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3812f8e2aace jenkins/jenkins:2.176.3 "/sbin/tini -- /usr/…" About an hour ago Up About an hour 50000/tcp, 0.0.0.0:9090->8080/tcp jenkins ---------------- root@3812f8e2aace:/# curl http://127.0.0.1:2375 curl: (7) Failed to connect to 127.0.0.1 port 2375: Connection refused – Salvio Sep 05 '19 at 10:59
  • I create a nginx container listen at port 80 and I use a tutum/curl to get it and it works. But when I try to perform a curl to docker address nothing happens whereas in local I get the endpoint /version. – Salvio Sep 05 '19 at 12:45
0

The container by default are launched by a bridge network. It was enough declare in docker run the option --network=host.

Salvio
  • 100
  • 2
  • 15