Site Loader
Auckland, New Zealand

Jenkins is one of the most popular CI/CD open source tool without any doubt. It has evolved so much in recent past that, the tool can be utilised with many modern way approach to build the application and deploy the application. Jenkins can be scaled with not just by installing different build agents in different machines, rather we can use the power of Docker containers to install agent and perform build operations effortlessly.

Docker plugin for Jenkins allows containers to be dynamically provisioned as Jenkins nodes using Docker. It is a Jenkins Cloud plugin for Docker

Architecture – Jenkins Master and Agent as a container

Complete architecture of how communication between Master and Agent happens from Docker

As you can see above, there are at lot of things going on, but here is the breakdown of each and every communication in high level

  • Docker for Windows needs to be installed within the Host machine (it can be a Windows 10/MacOS/Linux machine), here I am using Windows 10 Host machine
  • Jenkins Master is actually running within Docker as a Docker container
  • Jenkins Agent is running within Docker as a Docker container
  • Now the Jenkins Master is communicating with the host Docker via Docker Demon in tcp://host.docker.internal:2375 which you can enable in Docker –> General as shown below
  • Once the Jenkins Master is connected with Docker Demon, it can then safely communicate with any containers running within that Docker host via the Demon, since it will have all the networking information to talk with different containers, in our case its going to be an Docker container running Jenkins agent.

How to link Jenkins Master with Docker Host Demon?

Well, that’s the easiest part, it’s using a Jenkins Plugin!!

Docker plugin for Jenkins

Docker plugin for Jenkins is the plugin you should be looking for to make it happen.

This plugin allows containers to be dynamically provisioned as Jenkins nodes using Docker. It is a Jenkins Cloud plugin for Docker.

The aim of this docker plugin is to be able to use a Docker host to dynamically provision a docker container as a Jenkins agent node, let that run a single build, then tear-down that node, without the build process (or Jenkins job definition) requiring any awareness of docker.

Once the plugin is installed, all we need to do is to configure Jenkins to add new cloud from Jenkins -> Manage -> System configuration and add new cloud as shown

As mentioned above, the Docker demon will be running on tcp://host.docker.internal:2375 which needs to be the Docker Host URI

We can actually ping, the Docker demon connectivity from our Docker container as shown below

Next up?

Now that we have connected Jenkins Master container with Docker Demon running on our Local machine, the next part is to connect Docker agent running as an container with this Jenkins master and perform a build operation

Video Demonstration

The above article is fully available along with video demonstration here in ExecuteAutomation YouTube Channel and as a series in Udemy and ExecuteAutomation Platform

Video demo in YouTube

Other Resources

Udemy Course: https://www.udemy.com/course/working-with-jenkins/

ExecuteAutomation Platform: https://executeautomation.com/course/jenkins

Post Author: Karthik kk

Leave a Reply

Your email address will not be published. Required fields are marked *