Skip to Content
Technical Articles
Author's profile photo Shwetank Verma

Jenkins on Docker Container

In this blog post, I will try to show how to get a Jenkins server running on Docker.

Introduction

Jenkins as stated in the documentation is –  A self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software.

Docker is a set of PaaS products that uses OS level virtualisation to deliver software in packages called containers.

Now, lets get started –

Perquisite – Docker must be installed.

Getting Jenkins Run

Get the jenkins image from docker hub(hub.docker.com) using the command –

docker pull jenkins/jenkins

It will pull the latest jenkins image from the docker hub with all the libraries on to our local system. This is a fully functional Jenkins server, based on the weekly and LTS releases.

docker images will show the list of images in your locally repository along with the image id.

We can run the docker container using the command –

docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts

In this command -p will publish the container’s port to the host i.e. 8080 port of the jenkins server running on docker. With this command we will get our jenkins server running on the docker container. BUT, the jenkins directory associated with this will be also on container and on deleting the container it will be lost.

This we can overcome by having a explicit volume(by using option -v to create a volume during docker run).

docker run -p 8080:8080 -p 50000:50000 -v /Users/Documents/jenkins_home:/var/jenkins_home jenkins/jenkins:lts

this will automatically create a folder ‘jenkins_home’ on the host machine, that will survive the container stop/restart/deletion.

We can also use docker volume instead of physical location.

docker volume create myvolume

docker run -p 8080:8080 -p 50000:50000 -v myvolume:/var/jenkins_home jenkins/jenkins:lts

 

On successful run, We will get Admin password(also can be found jenkins_home/secrets/initialAdminPassword) which will be used to login to Jenkins server.

 

 

Lets hit localhost:8080

After unlock, install plugins if needed, and then create username and password for the jenkins server.

 

Woahhh !!! Jenkins is ready to be used now…

 

Please note we can start or stop our jenkins server by its container id.

check for the container id of our jenkins server –

docker ps

Stop the server – docker stop <container_id>

Start again server –  docker start <container_id>

Conclusion

We have set up a Jenkins server on a Docker. With this way we can have more control over our server as we are using our own Docker containers. Jenkins server can be tweaked with more configurations as per our need with more control on our docker containers.

In future post, we will see how to set up scalable infrastructure to host our Jenkins server.

Reference

https://hub.docker.com/

https://jenkins.io/

https://en.wikipedia.org/wiki/Docker_(software)

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Richard Birenheide
      Richard Birenheide

      Hi,

      if one wants to use this for long term projects, what would be the preferred route to update Jenkins itself? Updates wouldn't be part of the volume and if one wants to migrate elsewhere one might face incompatibilities with the plugins.

      I once migrated an workspace of an older Jenkins installation to a (much) newer version and the compatibility of the plugins used turned out to be a major headache.

      Kind Regards
      Richard

      Author's profile photo Shwetank Verma
      Shwetank Verma
      Blog Post Author

      Hi Richard,

      Thanks for your comment. To upgrade Jenkins we can do the following :

      docker stop jenkins-blog

      docker rm jenkins-blog

      docker run –name jenkins-blog -p 8080:8080 -p 50000:50000 \                                                                              -v myvolume:/var/jenkins_home \                                                                                                            jenkins/jenkins:2.xxx.x

       

      We can also automate the upgrade of jenkins in docker. I will try to show that in my future posts. Thanks.

       

       

      Author's profile photo Witalij Rudnicki
      Witalij Rudnicki

      Fyi, for more generał Docker understanding I publish series https://blogs.sap.com/tag/understandcontainers/

      And what a coincidence: Jenkins is using OrientDB as embedded storage 🙂