Using Docker with Jenkins » History » Version 5

« Previous - Version 5/7 (diff) - Next » - Current version
Seth Graham, 03/15/2016 04:57 PM

Using Docker with Jenkins

The build node buildservice008 has been installed with SL7.2 and is running Docker, allowing the specification of builds that run inside a Docker Container. This feature is provided by the "docker-custom-build-environment" plugin, which is documented here:

It allows the creation of a temporary Linux host, using any Linux distribution, and running a build job inside of it.

This offering is currently in a testing/provisional phase and comes with some limitations.


a) Containers are unsupported. You are in effect consenting to be a system admin, and will need to do whatever work the container requires to be able to run builds: install packages, configure software, and manage directory structures.

b) There is no shell access to the containers. Administration tasks will need to be done within the DOCKERFILE or by the build itself.

c) You will need to create a "jenkins" user inside your container. UID/GID should be 500. Without this, your job will probably crash.

d) All containers are firewalled. No inbound connections are permitted. Outbound connections are permitted.

e) No NFS mounts (including bluearc). As the containers don't exist as registered linux hosts, it's not possible to export NFS shares to them. Builds will have to pull in everything they need via ssh or wget.

f) CVMFS is not offered. It may be possible to configure CVMFS inside the container but you will need to configure it yourself.

g) Production of artifacts does not seem to work. This might be fixable with some tinkering.

h) Containers are not guaranteed to be persistent. 1TB of storage has been allocated to containers so they won't be deleted constantly, but your builds will not be able to assume a container it used previously (and the data inside it) still exists and it may have to re-create it.


a) Inside the Jenkins web interface on buildmaster, you configure a build to use docker inside the project's configuration page. A number of new options have appeared in the configuration, but only a few are required to actually get things going:

  • Check the "build inside a docker container" box.
  • Pick a docker image. "Pull docker image from repository" is recommended, but requires having a dockerfile set up. (see below)
  • The "Docker Host URI" field must be set to "tcp://" so Jenkins can communicate with docker on buildservice008.
  • You must add a "Volumes" entry to map buildservice008's /tmp to the container's /tmp. Without this, Jenkins won't be able to run the build script. Just type '/tmp' in both text boxes.
  • You will also want to restrict where the build can run. Check the "restrict where this build can run" box and add the 'docker' tag. The "docker" tag has been added to buildservice008 so if you use that, builds that use docker will always go to that host.

b) DOCKERFILES are the most effective way to customize a container. There is some documentation for these configuration files found here:

Add this file to your git repo, and in the "Docker image to use" section of your project configuration, specify the name of the file. When the build is run this dockerfile will be parsed and executed. The Jenkins Docker plugin will re-run this script every time the job is built, allowing you to make changes.