Github+jenkins+docker

Github+jenkins+docker

This article is a simple integration of GitHub, Jenkins and Docker to automate the process of deploying a website by creating custom Docker images using Dockerfile.

About the Task:

  1. Create a container image that’s has Jenkins installed using Dockerfile. When we launch this image, it should automatically start the Jenkins service in the container.
  2. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins 
  3. Job1: Pull the Github repo automatically when some developers push the repo to Github.
  4. Job2: By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code. Here my file is of HTML, hence Jenkins should start the container that has an interpreter (I made a custom httpd image) already installed.
  5. Job3: Test your app if it is working or not.
  6. Job4: if the app is not working, then send an email to the developer with error messages.
  7. Job5: Create One extra job not belonging to the pipeline to monitor: If the container where the app is running. fails due to any reason then this job should automatically start the container again.

Start the task :

Docker image for launching Jenkins as soon as the docker environment is run.

No alt text provided for this image

Now we build this image in the name of jenkinsos1:k1.

No alt text provided for this image

Building of Dockerfile will take some time now we run this container and expose to port 2222 for accessing webui of jenkins.

No alt text provided for this image


Jobs are created in this container and the necessary plugins like Build pipeline, Git, GitHub are installed.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

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

No alt text provided for this image
No alt text provided for this image

We use GitHub PollSCM this job meaning whenever there is a push to this repo, Job1 will clone the repo and copy the HTML file into a local repository called /root/files in my case.

Job2: By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code. Here my file is of HTML, hence Jenkins should start the container that has an interpreter httpd already installed.

No alt text provided for this image

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

No alt text provided for this image

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

Here, in my case it is working fine.

# For Configure Email Notifications Go to jenkins.

No alt text provided for this image

And now is the time for Job5: Create One extra job not belonging to the pipeline to monitor: If the container where the app is running fails due to any reason then this job should automatically start the container again.

We check if the **html is running every minute and if it fails a new container is created with the same name. This is an overhead for Jenkins and a better monitoring tool/method can be implemented.

No alt text provided for this image

**Now the pipeline is complete and it looks like this

No alt text provided for this image

 Our task of automation is complete and whenever there are failures or shortcomings, Jenkins jobs will notify us and the necessary action can be taken. It also monitors the container for whether its running or not!

Github Repo link:


Ravi Malvia java -jar expects a jar file name, in this case, jenkins.war.An executable Java program can be packaged in a JAR file, along with any libraries the program uses. 

Miss Shweta Bhardwaj can you tell me what is for net tools in dockerfile

To view or add a comment, sign in

More articles by Shweta Bhardwaj

Others also viewed

Explore content categories