About #jenkins

Build docker images with Jenkins running in docker

#jenkins / Jan 21, 2018 / 3 min

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:

  1. Install docker in your container.
  2. Expose docker socket (/var/run/docker.sock) to the Jenkins container.
  3. 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 ;)

Read the article