Basically, you can’t run a docker engine in a docker container, but in some use cases, you might still want to call docker client to build image and run container. In my use case is that I use docker executor in GitLab runner, and my apps are all deployed in docker containers, so I have to call call docker within the container at the deploy sequence.
The good thing is, docker client and docker engine can be seprated, and you can mirror the /var/run/docker.sock in container with the one your host machine which a docker engine runs within through docker volume.
In order to do the volume mirror, I edited the gitlab-runer config after it is configured as below.
1 | concurrent = 1 |
- I used the official docker image which contains a docker client, of course you can build customed image with docker client installed within, that is easy.
- I mirrored the host’s /var/run/docker.sock to gitlab-runner’s executor container so that the docker client in container can be used with a running docker engine. You’re welcome to do the config this volume in any other way you use docker like
docker run
ordocker-compose
.
To build a customed image with docker client is simple, you just do the COPY like what I do in the Dockerfile given below.
1 | FROM YOUR_IMAGE |