DevOps Task with Docker & Jenkins

Problem Statement:-

1. Create container image that’s has Jenkins installed using Dockerfile

2. When we launch this image, it should automatically starts Jenkins service in the container.

3. Create a job chain of job 1, job 2, job 3 and job 4 using build pipeline plugin in Jenkins

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

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

6. Job 3 : Test your app if it is working or not.

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

8. Create One extra job job5 for monitor : If container where app is running. fails due to any reason then this job should automatically start the container again.


First we will create a Dockerfile using centos and jenkins.

FROM: The image which is to be used for container.

RUN: Commands to be executed while building the modified container.

We will be installing wget & net-tools commands for downloading jenkins, java and various other repos and then downloading them.

COPY: This Command will be used to copy files from host to image while building it.

CMD: The cmd used here will keep the Jenkins live till the container is on and will start on container boot.

and the file :

For Building the image we use the following command:-

docker build -t jenkinstask:v1 .

After successfully building the image. We will be able to see this page:-

Now we will run our container as privileged and pat it:-

docker run -it --privileged -p 9999:8080 -v /:/host jenkinstask:v1

Now it’s time to move for the jobs :-

First Job:-

Added the job to newly created build pipeline view.

Now, Job 2 →

As soon as Job 1 completes, it will deploy the php container on the system.

Now, Job 3 →

This Job is for testing purpose.

Now Job 4 →

Finally, the last job: Monitoring Job 5 →

Final view of the Build Pipeline →



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store