Example of running Jenkins CI in a Docker Container
This repository contains example Docker recipes and supporting scripts that demonstrate running Jenkins CI that creates and runs Docker contains within build projects, with the Jenkins CI server itself running in a Docker container. Essentially this is a demonstration of the creation and use of sibling Docker containers.
Requires Docker 1.11 or later.
Tested on OS X El Capitan (10.11.5) using a boot2docker VirtualBox VM, and on Windows 10 Enterprise using a boot2docker Hyper-V VM.
Extension of example from The Docker Book
This example is inspired by the Jenkins CI examples from the Testing with Docker chapter of James Turnbull's The Docker Book (version 1.9.1). I've forked the Git repository he used in the book so that there is a version that stays synchronized with this example.
The example in the book used a technique called "Docker in Docker", in which a Docker container is running its own Docker daemon by which child containers are created. That approach turns out to lead to data corruption if you are not careful.
This reworked example avoids the "Docker in Docker" approach, and instead just shares the host Docker daemon port with the Jenkins CI container. The Docker client in that container will then communicate with the Docker daemon on the host, the same daemon that started that Jenkins CI container. New containers that are started from within the Jenkins CI container are started by the host Docker daemon and are sibling containers. This approach avoids the concurrent access issues and other incompatibilities and race conditions that would lead to corrupted data.
How to perform the examples
- Build the base Ubuntu image by
- Build the base Docker image by
- Build the data volume container by
- Build the Jenkins CI image by
- Launch the Jenkins CI container with
- Follow the procedures described in the Jenkins CI examples at the end of the Testing with Docker chapter of The Docker Book.