Jenkins With Docker
Updated: Sep 1, 2020

There is no doubt in the fact that all development is moving towards containerization. Jenkins have built in plugins available that makes its integration with docker seamless.
In this article we are going to study how things actually work.This article is a hands on lab .
Task: In this article we are going to deploy a nodejs app (that is running as docker container) on our production server) through a Jenkins pipeline.
Code: Working code can be cloned or forked from below github repository.
yum install git -y
git clone https://github.com/technoroots/devops-jenkins-docker-app.git
For this we need to do below configuration to Jenkins.
Configure Jenkins credentials for the production server. Here production server is the same Linux server on which Jenkins is hosted.
Configure Jenkins credentials for the docker image registry
Create a multi branch pipeline project in Jenkins called train-schedule
Configure Jenkins to pull from the source code from git and run the pipeline
2. We will define below stages in Jenkins pipeline
Build docker image
Push docker Image (Push the image to docker Hub)
Deploy to production server
3. Let us start with the lab now. In the last articles, we already studied about Jenkins
installation on a CentOS 7 box , the same machine we are going to use here as well.
4. Create ID on hub.docker.com (I am using the id prashanti2689)
5. In the current setup node1 is our jenkins server and we will deploy the app on the
same server.
6. Install docker, start and enable the service.
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker
systemctl status docker
7. Go to Jenkins home page -- Manage Jenkins -- Manage Plugins -- Click on
Available Search and select following plugins
Docker Common
Docker API
Docker Pipeline
Docker-build-step
Image Tag parameter
8. Now create a github personal access token for your account and provide it in
jenkins credentials. (Refer the last tutorial to know how to do it)
9. Now go to the Jenkins homepage -- Click on new Item -- Give the project name as
train-app-docker-deploy -- Select project type as Multi-branch pipeline -- Branch
source as github.

10. Now build the job and wait for some time. In this build , docker image will be created
from the Dockerfile and pushed to the repository.

11. We can verify that by opening our Docker Hub repository. Also, image will be pushed
there inside the repository.


12. Now open this URL in the browser (http://node1:10000) and we will be able to see
the train schedule app.
Congratulations !!! We just deployed a nodejs containerized app via jenkins and
moved a step ahead in our journey with Jenkins.
In the last lecture of this series coming up soon we will see how docker and
kubernetes work together and makes life easy. Till then take care and happy
learning :)