HI All, this document deals with how to build and push docker image to docker hub using Jenkins.
Docker is a computer program that performs operating-system-level virtualization, also known as “containerization”. It was first released in 2013 and is developed by Docker, Inc. Docker is used to running software packages called “containers”
Jenkins is an open source automation server written in Java. Jenkins helps to automate the non-human part of the software development process, with continuous integration and facilitating technical aspects of continuous delivery. It is a server-based system that runs in servlet containers such as Apache Tomcat.

Prerequisites:

* Running Jenkins Server
* Java application code in GIT, here I’m using SCM as Git, you can use SVN as well. If you are using SVN as your SCM make sure you have installed SVN plugin.
* You need docker hub registry with credentials.
* make sure that you have dockerfile inside your repository.
* install cloud bees Docker plugin

My Sample Code can be found in this repository:  https://github.com/prabhinmp/maventest.git

Configuration

Step 1: Configure your credentials for SCM and Docker Hub in Jenkins server. You can do this Goto credentials from Jenkins main dashboard.
Step 2: Create a repository in the Docker hub to store all your images.


Step 3: Now Goto Jenkins create the job.


Step 4: In source code management select Git, it may differ in your case.
Step 5: Enter the repository URL and associate the SCM credentials.


Step 6: Since I’m using Maven for building the Java application so I’m using the maven plugin to build the app. so the build section in Jenkins will be like this.


Step 7: Now we have to add build post steps and make sure that post step should execute only after Build Sucess.
Step 8: In build post step select docker build and publish option and enter the following details,
repository
tag
credentials
Refer the below image for further reference

Step 9: Now save and apply
Step 10: Now start the job and wait for the job to get the finish.


Step 11: Once the job finished successfully, login to docker hub you can see the image uploaded to Docker hub with the tag as below.

Now you can take this image and deploy in any host as per your requirement.

 

© 2019, Techrunnr. All rights reserved.

#1
#2
#3
Questions Answered
Articles Written
Overall Points

Prabhin Prabharkaran

He is Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!!

Leave a Reply

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.