Container of the Week – jenkins

This post is part of a series where we examine a different container image each week.  See previous Containers of the Week here. This week’s image is the official image for the Jenkins project, an open source application for building, deploying and automating software.

Running Jenkins inside a container is a simple task, but I’m going to give you a few tips to improve your Jenkins experience with Docker.

When I have previously used Jenkins it was a matter of starting up a virtual machine, installing a JVM, and downloading and unpacking a giant tarball of files from the  Jenkins website.  Today this has all been replaced with a couple of Docker commands:

$ docker pull jenkins
$ docker run --name jenkins -p 8080:8080 \
    -v ~/jenkins_home:/var/cache/jenkins_home jenkins

Point your web browser at http://localhost:8080 and in minutes you have a fresh Jenkins server.

There are a few tricks to getting Jenkins working well under Docker.

  • Map the /var/cache/jenkins_home directory to a volume on your host. All the useful Jenkins data such as job configuration, build logs and build artefacts are all stored here. If you don’t make this directory persistent all this information is lost when the Jenkins container is removed.
  • Install the Docker Jenkins plugin. This plugin allows Jenkins to dynamically create slaves inside Docker containers. A Jenkins job build runs inside the container and is removed when it completes.

The Docker Jenkins plugin is quite interesting. If your jobs can be run inside a container, then it’s possible for your entire Jenkins system to run inside Docker!

In the past I have had to deal with bare metal and virtual machines running Jenkins servers and slave nodes along with the usual hassle of long-term maintenance of servers. If you just need to run Jenkins locally then running both the master and slave nodes can save a lot of time.