├── Dockerfile ├── README.md └── supervisord.conf /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM jpetazzo/dind 2 | 3 | MAINTAINER Decheng Zhang 4 | 5 | ENV SWARM_CLIENT_VERSION 2.0 6 | ENV DOCKER_COMPOSE_VERSION 1.3.3 7 | 8 | # Add a Jenkins user with permission to run docker commands 9 | RUN useradd -r -m -G docker jenkins 10 | 11 | # Install necessary packages 12 | RUN apt-get update && apt-get install -y curl zip openjdk-7-jre-headless supervisor && rm -rf /var/lib/apt/lists/* 13 | 14 | # Install Jenkins Swarm Client 15 | RUN wget -q http://maven.jenkins-ci.org/content/repositories/releases/org/jenkins-ci/plugins/swarm-client/${SWARM_CLIENT_VERSION}/swarm-client-${SWARM_CLIENT_VERSION}-jar-with-dependencies.jar -P /home/jenkins 16 | 17 | # Install Docker Compose 18 | RUN curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose 19 | RUN chmod +x /usr/local/bin/docker-compose 20 | 21 | ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf 22 | 23 | CMD ["/usr/bin/supervisord"] 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jenkins Slave DinD (Docker in Docker) 2 | 3 | This Jenkins Slave Docker image inherits the same idea as [the master one](https://hub.docker.com/r/killercentury/jenkins-dind/) that provides Docker Engine and Docker Compose inside itself, which allows you to run anything via Docker container in your Jenkins build script. So it also means that you don't need a custom build of Jenkins that pre-install any build tool or runtime anymore. You can provide all these via Docker images in your build script, which guarantees a highly isolated environment between jobs as well. 4 | 5 | This Docker image is based on [jpetazzo/dind](https://registry.hub.docker.com/u/jpetazzo/dind/) to provide the DinD (Docker in Docker) environment. [Supervisord](http://supervisord.org) is used to make sure everything has proper permission and launch in the right order. [Jenkins Swarm Client](http://maven.jenkins-ci.org/content/repositories/releases/org/jenkins-ci/plugins/swarm-client/) is used to connect with the master in an intelligent way. Moreover, [Docker Compose](https://github.com/docker/compose) is available for launching multiple containers inside the CI. 6 | 7 | This Jenkins slave image should be able to connect with any Jenkins master with JNLP enabled, such as [killercentury/jenkins-dind](https://hub.docker.com/r/killercentury/jenkins-dind/) and normal Jenkins installed manually or via package manager. 8 | 9 | ## Usage 10 | 11 | The environment variable COMMAND_OPTIONS has to be specified with non-empty value, which is a combination of all swarm client options you need. Please refer to this [Swarm Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Swarm+Plugin) for all available options. 12 | 13 | Following is an example of command used to connect with the master: 14 | ``` 15 | docker run --name jenkins-slave-dind --privileged -d -e COMMAND_OPTIONS="-master http://YOUR-JENKINS-MASTER-HOST:YOUR-JENKINS-MASTER-PORT -username YOUR_SLAVE_USERNAME -password YOUR_SLAVE_PASSWORD" killercentury/jenkins-slave-dind 16 | ``` 17 | -------------------------------------------------------------------------------- /supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | 4 | [program:docker] 5 | priority=10 6 | command=wrapdocker 7 | 8 | [program:swarm-client] 9 | priority=20 10 | user=jenkins 11 | environment=HOME="/home/jenkins",USER="jenkins" 12 | directory=/home/jenkins 13 | command=java -jar swarm-client-2.0-jar-with-dependencies.jar %(ENV_COMMAND_OPTIONS)s 14 | --------------------------------------------------------------------------------