How to run a docker container from another docker container?
Create a docker image which runs jenkins. A jenkins task will prepare a data folder to be used along with another docker container. At the end the two containers will run side by side. The container spawned by the jenkins container has a limited life time and will die by itself if unused.
⚠️ Former versions of this post advised to bind-mount the docker binary from the host to the container. This is not reliable anymore, because the Docker Engine is no longer distributed as (almost) static libraries.
host $ docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock alpine sh / # docker sh: docker: not found / # apk update [...] / # apk add docker [...] / # docker images [...] *works*
Don't forget this quote. See :
Yes, anyone with direct access to the Docker socket has root privileges on the host system. Usually not what you want.
|||Nathan Leclaire, Docker forum "How can i run docker command inside a docker container?", https://forums.docker.com/t/how-can-i-run-docker-command-inside-a-docker-container/337/5|
|||Jérôme Petazzoni, "Using Docker-in-Docker for your CI or testing environment? Think twice.", https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/|