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.