Theory

There is no way to actually run a docker daemon in a container, but we can pass docker cli and docker daemon through volume mirroring.

Example

Let’s run a container along with those we need mirrored.

1
2
3
4
docker run -it \
-v /usr/bin/docker:/usr/bin/docker \ ## mirror docker cli
-v /var/run/docker.sock:/var/run/docker.sock \ ## mirror docker.sock
ubuntu /bin/bash

Inside this container we can actually call the docker cli.

1
2
3
4
5
[email protected]:/# docker info
Client:
Context: default
Debug Mode: false
## other info ...

Use Case

The reason for me to do this is that I want to call docker cli in a gitlab-runner/docker executor during pipeline. The executor itself is a docker container.

Thus, I configured the runner this way:

1
2
3
4
5
6
7
8
9
[[runners]]
[runners.docker]
image = "ubuntu"
volumes = [
"/usr/bin/docker:/usr/bin/docker",
"/var/run/docker.sock:/var/run/docker.sock",
"/usr/local/bin/docker-compose:/usr/local/bin/docker-compose",
"/cache"
]