
This article describes the use of docker containers as separate nodes for a continuous integration system, in this case jenkins. Too lazy to read
tl; drTo build our project in RPM and DEB packages we use Jenkins, for which a special machine is allocated.
At first, we collected our project only for CentOS 6. Then CentOS 5 support was added, and it turned out that depending on specific versions of libraries do not allow the same binaries to work under different versions of CentOS, we needed to build different RPMs. This was decided by adding nodes to the jenkins with CentOS 5, which was served by the VirtualBox virtual box. Then added support for Suse, and then Debian.
The amount of RAM is not rubber, and using virtual machines only for building is an obvious overhead, and it was decided to rewrite the scripts using
Docker .

Using Jenkins for continuous integration, you can connect nodes with the necessary operating systems and assign tasks to them, there are several options:
- Rent instances / computers and use them as nodes
- Use standard virtualization (hypervisor)
- Containers (lxc, jail etc)
The advantages of containers over virtual machines are obvious in this case (the RAM is shared, dynamically changing, a large number of lifted containers do not slow down the system, unlike virtual machines), and Docker adds to them such important points as:
')
- To build the project, the actual build script runs, and nothing more. Whereas when using a virtual machine, all system processes and daemons will be started, which eats away host resources.
- “Cheap” creation of a large number of independent clones of machines - sometimes for assembling a project you need an isolated environment for assembly.
Docker as a jenkins node
For jenkins-slave we need:
- Java
- Entry Point - ssh
- Assembly tools
The entry point is needed to start the process in docker and save the file system within the build session (LXC uses the init process, but the whole system does not need anything). Since jenkins will still need SSH to communicate with the node, this daemon will be the entry point.
Docker suggests using Dockerfile files with instructions for building the machine to build the machine.
In this repository:
https://github.com/antigluk/docker-jenkins-slave now build rules for
- CentOS 5
- CentOS 6
- Suse 12
- Debian 6
Pull-requests with new systems, and bug fixes are welcome :)
Assembly and use
It is assumed that you have Docker and Jenkins installed
1) Install the Jenkins
Swarm Plugin (it allows slaves to be added to Jenkins automatically using the API)
2) $ git clone git@github.com: antigluk / docker-jenkins-slave.git; cd docker-jenkins-slave
3) Go to the folder with the rules for the desired system
$ cd centos6
4) $ sudo bash build.sh
When the image is assembled, you can add as many nodes of this type as you like:
sudo bash add_slave.sh SlaveName
After executing this command, you should see the new node on Jenkins-e.
Now, to use a new node, it is enough to indicate in the tags for assembling the necessary task “docker-tagname” - the name of the tag is the name of the system with the full version, the list of tags can be viewed
on a special page in the wiki