Docker:Dind - Volumes provided in config.toml attaching to client container not to dind container.
I am trying to build a pipeline with Gitlab-CI in which pipelines get executed faster with built image's caching on Docker Host and have different stages for every testing so individual errors get caught early. Pipeline: I wanted to build a test_image once early in the pipeline and use it for the next jobs/stages.
Below I am listing some of the configurations I used on both of the below-listed environments. For Gitlab CI .gitlab-ci.yml
For Gitlab-runner Configuration. config.toml
Tested Environments:
- Windows OS - With Docker Toolbox for windows and Gitlab Runner for Windows. (APPROACH WORKS FINE FOR THIS.)
- Ubuntu OS - With Docker/Docker-compose and Gitlab Runner on the system. (NOT WORKING)
Windows OS working: I tried an approach by specified volumes(/image/cache:/var/lib/docker/image) in config.toml for runner and i got a volume directory of Docker HOST (/image/cache) mounted to DOCKER:DIND service container(/var/lib/docker/image). Benefits I got:
- Image built once can be used in the next stages.
- Faster rebuilding images.
- Faster CI Pipeline.
- Except for images everything is from clean slate which we can delete at any stage.
But this approach didn't work on Ubuntu Gitlab-runner. Ubuntu OS working: The above approach didn't work as on ubuntu we have 2 containers(Docker:Dind and docker client(i.e. docker/compose)) running on the Docker host. So the above-described volume gets mounted to the docker-client container but not to the docker:dind container.
Questions:
- Is this the desired behavior? If no, How can I fix this to connect volumes to dind container running as service (Should I use dind as an image?)?
- If yes, How can I construct my desired pipeline in which I can save time too?
- Or Should I not use the dind service and lose the ability to use shared runners as there is a chance of code exposure?