Aktualisiert: 20. Dez 2019
I've seen a lot of people ask the question, how to execute docker inside of a docker container and there can actually be a use case for that.
The most obvious use case for me was a Jenkins container, that needs to execute docker commands in order to build and push the image in docker repo in its build jobs.
There are 3 ways to do it:
get a ready Jenkins image with docker pre-installed
install docker yourself in the Jenkins official image (by adjusting the Dockerfile and rebuilding the image)
use docker installed on the host where the container is running. -> This is the option I have used
In order to get the docker from host into the container, you need to mount the docker installation path on the host into the Jenkins container.
- image: jenkins
- mountPath: /var/run/docker.sock
- name: docker-sock
Now when this Jenkins container starts you will have docker commands available inside.