Control docker from the inside

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.

See [1]:

⚠️ 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

Don't forget this quote. See [2]:

Yes, anyone with direct access to the Docker socket has root privileges on the host system. Usually not what you want.


[1]Nathan Leclaire, Docker forum "How can i run docker command inside a docker container?",
[2]Jérôme Petazzoni, "Using Docker-in-Docker for your CI or testing environment? Think twice.",