Note: this is part 4 in a series of Docker Tutorials.
You want to set up your dockerized Jenkins server via Jenkins Configuration as Code (JCasC) such that it dynamically creates Docker slaves whenever it executes a job.
TLDR: Bitbucket code.
This can be achieved with the docker-plugin and the corresponding YAML code block in your JCasC configuration file.
Continuing where we left off, we need to
- add the docker-plugin to our plugins.txt file
- extend our initial Dockerfile by installing the Docker Commandline Interface
- bind-mount /var/run/docker.sock into our Jenkins Docker container so that we can make use of the Docker daemon running on the host machine
- add the docker-plugin settings to our JCasC jenkins.yml configuration file
We will skip step 1 because it is straight forward.
Step 2 leads to the following Dockerfile