1

I installed Docker on Windows 10, and I pulled jenkins docker from Docker Hub. Next, I started my jenkins docker,

docker run --rm -u root -p 8080:8080 -v my_host_path:/var/jenkins_home jenkins

Next, I used Manage Jenkins and Manage Plugins to install Docker plugin, then went to the Configure page and tried to add Docker Cloud.

After I entered Docker Host URI : tcp://127.0.0.1:2375, I wanted to "Test Connection", but unfortunately got failed.

I tried to follow the instruction as below link: How to find "Docker Host URI" to be used in Jenkins "Docker Plugin"?

But I can't not find any docker setting file under /etc/default/* in my jenkins container, so I can't set the DOCKER_OPTS argument.

Could someone give me any advise? Thank you !

Lester_wu
  • 151
  • 5
  • You need to look for that file on docker host i.e. on Windows 10 not within the docker container – ben5556 Dec 10 '18 at 06:38
  • I check Docker Desktop > Settings > General > **Expose daemon on tcp://localhost:2375 without TLS**, and restart my container, but it still failed to **"Test Connection"**. Besides, I tried to find the file on Windows 10, but I can't find any related file which can set the argument (I've check C:\ProgramData\DockerDesktop, C:\ProgramData\Docker). Does anything I miss? – Lester_wu Dec 11 '18 at 01:20

1 Answers1

1

Problem context: end of Chapter 3 exercise from the book "Continuous Delivery with Docker and Jenkins" by Rafal Leszko

from Configure and troubleshoot the Docker daemon page

Important: Setting hosts in the daemon.json is not supported on Docker Desktop for Windows or Docker Desktop for Mac.

Setting the docker host uri does NOT work on Windows. So either of these won't work in the Settings > Daemon tab:

  1. "hosts" : "-H tcp://0.0.0.0:2375"
  2. "DOCKER_OPTS" : "-H tcp://0.0.0.0:2375"

Exposing the daemon without TLS (checkbox on General tab) as recommended in some places did not work for me either.

The solution to connecting the Docker plugin in Jenkins with the docker host, is: use the special DNS name host.docker.internal

From the docs:

How do I connect from a container to a service on the host? Windows has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS name host.docker.internal, which resolves to the internal IP address used by the host. This is for development purposes and will not work in a production environment outside of Docker Desktop for Windows. The gateway is also reachable as gateway.docker.internal. For more information about the networking features in Docker Desktop for Windows, see Networking.

While the 'will not work in a production environment outside of Docker Desktop for Windows' disclaimer might bother some, I believe Docker for Windows is not meant for production use cases anyway.

Additionally, publish this mapping for Jenkins agent-master communication -p 50000:50000

Nikhil Silveira
  • 504
  • 4
  • 14