Skip to main content

Using Jenkins to Build and Deploy Docker images

How to use Jenkins to Build and Deploy docker images without Jenkins Docker plugin

Introduction

Jenkins is one of the most popular continuous integration tools and is widely used. It can be used to create pipelines, run jobs and do automated deployments.
There are many plugins available which can be added to Jenkins and makes it really powerful.

Recently I wanted to do an automated deployment of Docker Images to docker server and tried using docker-plugin but after spending some time it looked to me that if it asking for too much of information and for each operation you need to provide arguments, I would prefer a solution which is more dynamic and picks things automatically with user providing the bare essentials parameters arguments.
This is how it looks like

 

In a nutshell, all I wanted was

  • Jenkins to automatically start building the Docker Image once the code is pushed to GIT.
  • The Image should be deployed to remote docker host and it should start the container

How to do it

  • Well, the first step is is to enable Jenkins to auto build with BitBucket server or other code repository server. If you want your build process to start as soon as the code is committed to GIT repository.
    Here is an example of how to enable with BitBucket Server, for other GIT repositories servers like GITHUB Jenkins does have different plugins.In case you want to build process to start manually or periodically you can skip this step.
  • Once the build is automated.The second step is to enable Remote API on Docker Host.Docker provides remote REST API which is beneficial if you want to connect to a remote docker host, this API allows you do to set of operations from creating and managing containers to start to stop containers.This step is pivotal before we move on to next step.
  • The third step is to modify your pom to build and deploy Docker Image, well this is the key step as in this step you will be literally doing all the stuff from creating the image to build the image and start the container.

    Once all 3 steps have been tested and completed all is left to be done in Jenkins is to Invoke the clean install goal as shown below.

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami