Setup Docker container as Build Slaves for Jenkins for a Dynamic Provisioning

Introduction

Today we will continue our journey to explore the fantastic world of DevOps with its automation tools. I would never stop tell you that in Production world, developers and engineers work on different projects, so they need various environment to accomplish their tasks in better and quicker record time.Therefore platform like Docker, kubernetes,… would help them to containerize and deploy their apps quicker and save money in case of resources.

Environment

For this demo, i will use:

  • And my local machine Ubuntu as a Docker engine server to provide containers for the Jenkins.

My Plan

So what is my plan?? i will submit a Job to Master node and as i don’t want this job to be executed in Master node ,therefore the Master node will look for Docker in a cloud (means i have to establish a connection between the Docker engine and the Master ) which will launch a container to run the jobs submitted in the Master node and as soon as the jobs terminated the container is removed from the Master ( Case of a Dynamic provisioning). And then after launch a maven app from github to test also our Docker container.

Step 1: Start the Jenkins service and login it

I had already made a write-up on how to install Jenkins on a machine go to see it at: https://tchamieedmond.medium.com/create-a-quick-distributed-multi-nodes-cluster-with-jenkins-using-a-master-node-in-rhel8-os-and-3-fe62caf2b340?source=your_stories_page------------------------------------- or you can use Official Doc from https://www.jenkins.io/download/

Jenkins service running and now login with this ip

Step 2: Install Docker Plugin in the Master node

Head over to Jenkins Dashboard –> Manage Jenkins –> Manage Plugins. And install docker plugin then after restart the jenkins service

Install docker plugin

Step 3: Start Docker engine service on my local Machine

I have already docker installed on my machine and i consider you too also otherwise i refer you to https://docs.docker.com/engine/install/ubuntu/

docker service running

Step 4 : Enable tcp connection on Docker engine

For that you have to go Docker service file and bind the tcp port connection. From below screenshot the config file of service is:

Suceessfully bind my local machine ip in Docker engine file

Step 5: Return to Master node to manage nodes by configuring Cloud

I want the Master to go another machine running docker engine and launch a container so for that we have to configure option cloud in master like:

Configure Clouds option

Step 6: Launch a freestyle project job to test our setup

Before launch the job, you can see we don’t yet have a docker container node available in our nodes

As i want to test our setup so feel free to give any command you want to be execute in the “Execute shell” field
Job running and immediatley a slave node is created in nodes tabs

Step 7: Let’s create a package and a test with our job from a Github maven app and our docker image

CONCLUSION

Congrats we made it. With this post you see effectively the power of a Dynamic provisioning with Jenkins along Docker, and know that’s one of show case of how we can integrate containerization with an automation tool to deploy an app in an environment.

3rd Year CSE Student, Technology Passionate(Docker, AWS, K8s,Rhel Linux,...), Aspiring Security Expert😁