This is a new example on how to use docker along docker without docker, confused?, I'm using the docker API to create and run containers.
In this particular example the image self-replicates itself running multiple images.
To build:
docker build . --tag twin-api:latest
The image uses an alpine based container with curl and jq.
To run:
docker run -ti -v /var/run/docker.sock:/var/run/docker.sock twin-api:latest [number of twin copies]
Example:
$ docker run -ti -v /var/run/docker.sock:/var/run/docker.sock twin-api:latest 5
Twin docker container running with id=41bdabc1db11af51150c347a1e64e5789257cb826e8c5508d4a152521573e0f7 (Iteration=5)
Twin docker container running with id=ee0aa9c45d36df4f076c79ba69bfe2e685279a5e2cbac2118fd6c3896d35fd88 (Iteration=4)
Twin docker container running with id=bfb390da9aa64c73ef738ae6a99edfe6cdea219fc3ea3e358a16d8e581d0a3ba (Iteration=3)
Twin docker container running with id=5da0748c7f03348800196b4a8b8a329924ee34429b0b77df0b475c43134316d0 (Iteration=2)
Twin docker container running with id=03f45e1d597a11d2a895762519596328973b7128fb243f4b185f59532928ab57 (Iteration=1)
One particular useful command to see what happens in the back of the conversation between docker-cli and dockerd is:
socat -v UNIX-LISTEN:/tmp/fake,fork UNIX-CONNECT:/var/run/docker.sock
And on another terminal:
DOCKER_HOST=unix:///tmp/fake docker ps .....
The scripts are self-explanatory.