sebastiandaschner blog


Jenkins as a docker orchestrator

#jenkins #docker monday, february 23, 2015

Continuous Integration / Deployment with docker is a hot topic in those days. Jenkins as a CI server is perfect to orchestrate applications which run in a docker container (e.g. different environments in the build pipeline with automatic system tests). One step further is to let Jenkins itself run in a container. Some small adjustments are needed so that the CI server is able to communicate with the docker host.

We do not want to run a container in a container here (hello, Inception) rather than running all containers on the same level.

You can achieve this by either letting the containers communicate via the docker REST interface or by adding the docker binaries to the container. The latter solution has the advantage that you don’t need the container to know the URL/IP of the host.

You add the binaries with something like RUN apt-get install docker.io in your Dockerfile.

You tell the container to use the host’s docker by connecting the docker Unix sockets:
docker run --rm --name ci-server -v /var/run/docker.sock:/run/docker.sock [image].

Afterwards you can simply run a script with docker commands in the Jenkins container and they will be run on the docker host.

 

Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java: