Using Jenkins with Docker

Written by: Michael Neale

3 min read

As I mentioned previously Docker is getting a lot of interest lately.

Docker kindly provide a trusted * build service which allows people to publish and share their docker images for quick reuse.

I have built two images for consumption, all you need is docker installed:

Jenkins in a

This is simply an "appliance" you can use to run jenkins - all you need is docker. This is really the same as what you would get if you followed the ubuntu/debian setup instructions and some work.

To use this, simply run:

docker run -p 8080:8080 michaelneale/jenkins-docker

This will download (and cache) and run a "vanilla" jenkins, inside docker. The workspace is stored in the docker container (the container is persistent). You can of course have it store the workspace anywhere you like, as normal. But the nice bit is that it is just one thing to run - and it will run anywhere docker runs - that is what docker is all about.

Running builds that use

One thing lots of people are looking at is using docker itself in jenkins builds (the docker plugin is a work in progress showing how to use a base image to host builds) - this requires you to wire it up to your docker installation.

This docker image (based on the above) also allows you to use docker itself as part of your build:docker run -p 8080:8080 -privileged michaelneale/jenkins-docker-executors

This, like the above, will leave you with jenkins running on port 8080 - however - note the privileged flag - that allows docker to run, itself, inside the container (crazy! - enabled by this ).

You can then create freestyle builds that use docker commands! This one is clearly more experimental than the first - use wisely (the privileged flag means that docker has less control over what the container can do).

UPDATE: here is a great article on running the docker plugin for jenkins - which can help you make use of images to run as build executors (like a little mini cloud).

So there you have it - 2 ways to use Jenkins with Docker. Docker images, published public index *, are an interesting way to distribute server based software - as you know, once it is built, it will work where docker works!

If you are using docker-osx - for example, you will find jenkins running on http://localdocker:8080.

These are not official distributions at the moment - and I hope to make these available under the cloudbees namespace/github group when the index supports this soon (at the moment they are under my name, but that is temporary) - but they aren't that hard to do. See here and here for the github repos. Pull requests welcome.

* The "trusted build service" by docker.io is not really so much about the building of image, but the fact that it builds images you can trust that do what the Dockerfile says they can do - so you can safely use the binary images just as if you installed a package via your OS package manager.

Stay up-to-date with the latest insights

Sign up today for the CloudBees newsletter and get our latest and greatest how-to’s and developer insights, product updates and company news!