Building docker images within the CI pipeline isn’t something new or unusual these days. Normally it’s super easy - you just have to install Docker in your Jenkins CI environment and add jenkins
user to the docker
group. Problems appear when your Jenkins instance is a docker container itself.
Inception begins
How to make docker
available inside your container? Here is a three steps solution:
- Install docker in your container.
- Expose docker socket (
/var/run/docker.sock
) to the Jenkins container. - Expose host’s docker executable (
/usr/bin/docker
) to the container.
At this point, you should already be able to use docker inside Jenkins’ container. Nevertheless, all docker commands executing by Jenkins must start with sudo docker
. That requirement has been greatly explained in Post-installation steps for Linux chapter of docker’s docs. If it fits your needs & security restriction you can stop here - but please know, that there is a better solution ;)