Integrating Docker With Jenkins:-Deploy Code With Respective Language Interpreter On Docker Container

Himanshu Agrawal
4 min readJul 11, 2020

Hello Everyone

Here is my Task2:
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 job1, job2, job3 and job4 using build pipeline plugin in Jenkins
4. Job1 : Pull the Github repo automatically when some developers push repo to Github.
5. 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 ).
6. Job3 : Test your app if it is working or not.
7. Job4 : 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.

Implementation :

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

When we launch this image, it should automatically starts Jenkins service in the container.It will install all the necessary software which we require in this task like jenkins, git, python 3, openjdk etc.

2. After build,when we run conatiner it will automatically start jenkins..

docker run -dit -p 8082:8080 — name myos -v /workstation/:/ws/ httpd

3. For creating a job chain of all the jobs using build pipeline plugin, we need to download a plugin called “Build Pipeline Plugin”

4.Create a (job1 ) that will download data from Github and then save it to our local folder

here i have used poll scm which will automatically check after every minute whether developer pushed code to github or not.

5.Create (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 ).

For launching the conatiners from the jenkins that also run in a conatiner..For that we do this with help of ssh..
For ssh we create ssh keygen

6.Create (Job3) : Test your app if it is working or not. If site is working properly then it will give status code 200 and if it is not working then it will give status code like 500. This job will check whether our job is running good or not.

7. (Job4) : if it is not working , then this job will send email to developer with error messages.

8. Create (job4:Monitoring Job):If container where app is running. fails due to any reson then this job should automatically start the container again.

9. Finally running the jobs using Build Pipepline…

Deployed website…….

Console Outputs……

Thank you so much for reading this article……

--

--