TASK2_MLOPS_INTEGRATING_JENKINS_WITH_DOCKER_CONTAINERS

Akshat Soni
5 min readJun 29, 2020

--

I have completed the task 1 month ago and after completing the MLOPS training. I came to know about the important twist in this task and I decided to work again on this task. I have read multiple posts but cannot find anyone who have done this task using a diff approach.

For building this project we need to create a container using dockerfile in which we have to install the jenkins. And it should start the jenkins service while running the container. After that we need to create the job chain of diff jobs in which we have to launch the container and do different tasks using it.

However doing the tasks this architecture will be like this. First we need to launch the container in which jenkins is preinstalled and then we need to create different jobs which includes running more docker containers in it.

This part is related to the concept of running docker inside a docker container.

docker inside docker

In the above picture I have run a container os1 from the baseos and then launch a new container os2 from the os1 and then when i again try to launch an os from os2 it shows failure.

I have read multiple posts in which almost 90% used the concept of changing the root directory. Also in some blogs the have mount the docker.sock file to the os1. Using this concept you can run the docker commands inside the container but it will work in the system of base os means you cant use the file which are inside the container.

I have done this setup without using the docker:dind version. Because I dont understand how that container works properly.

Here I have used the concept of docker proxy while creating a container and I am able to run the docker containers as you can see in the above ss. But I am not sharing that code because i still have some doubts. After understanding some more concepts I will share it on my github account. And for the docker proxy concept I will write a separate blog.

Now I am sharing step by step all the screenshots of different jobs of jenkins that are properly working in the os1 container

First i uploaded my code to the github.

Job1 : Pull the Github repo automatically when some developers push repo to Github.

Job2 : By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).

Job3 : Test your app if it is working or not.

I have combined these two jobs and created one simple logic that if the ls command finds a file of .php extension or .html extension then they will run the customized docker containers in which the httpd and php are pre installed. At the same time it will check the page (httpd server) or interpreter(php). And they will run successfully after exits giving a failure.

It means if their is some problem in code then it will exit giving a successfull build which will trigger the next job for sending email to the Developer.

Job4 : if app is not working , then send email to developer with error messages.

In this job also i have used exit 1 so that it will give the failure after exiting and send the email

Job5: If container where app is running. fails due to any reason then this job should automatically start the container again.

In this job if the container (php or httpd) is not running than it will restart the Container.

I’ll share the complete code for the jenkins job and for creating the docker proxy after resolving my doubts.

I have completed this project with my friend Aditya Sharma

And thanks Priyansh sir for your guidance.

LinkedIN profile: https://www.linkedin.com/in/akshat-soni-011b461a6

Github: https://github.com/akshat-crypto/task2

--

--

No responses yet