-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify GitLab CI documentation #1016
Conversation
I just created this example project on Gitlab. |
Hey @TjeuKayim, I'm normally just a Gitlab on-prem user, using Docker socket mounting, so I was never sure what's the best way to achieve this in Gitlab cloud. But I think your example is definitely nicer as the current one, so thanks. |
Another working example: In reply to #967. |
Maybe we should recommend this new configuration in the docs, but also mention the old configuration as an alternative. |
I'm kind of wondering how file mounting works for both configs. I kind of assume it's not working for both examples, since the DinD is another container? |
It’s indeed a bit mysterious how that old configuration worked. I’m not a Docker expert either. |
@kiview either Gitlab configures current directory and one-to-one path mapping or that example project is not mounting any files |
Both the previous and the new Gitlab CI configurations support the use of |
@bsideup I think Gitlab has some special hacks for DinD service, that will automatically mount stuff from build container into DinD container. I'll try to check in the Gitlab sources later. Nevertheless, I think this example config is better for the general Gitlab DinD user, so I'd like to merge it. |
Okay, found the explanation in the Gitlab docs:
See: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kiview looks good to me 👍
@TjeuKayim extra points for testing it 👍
4dcd7eb
to
4b77ebc
Compare
Nice! Thanks a lot for this @TjeuKayim - it's much nicer to read. 🙇 |
Last week, I spend some time figuring out the best configuration for GitLab CI and DinD. At first, I used the example in the docs. Then I tried other ways.
As it turns out, the documented GitLab configuration is over-complicated. It uses three containers (
docker:latest
,gradle:3.4
,docker:dind
) and runs docker in a script, but that extra layer is unnecessary. By setting theDOCKER_HOST
environment variable, you only need two containers.This is a simpler alternative configuration:
This configuration is more readable, and has better performance. That's why I suggest to update the documentation for using Gitlab CI.
How the previous configuration operates
Disclaimer: I'm not a Docker expert.
Let's take this configuration as an example:
The
docker run
command uses the daemon specified by theDOCKER_HOST
environment variable.At Gitlab CI,
DOCKER_HOST
defaults totcp://docker:2375
if you define adocker:dind
service (proof).If you don't define such service, it will be empty.
So in the example above,
docker run
will use the Docker daemon inside thedocker:dind
service (with default hostnamedocker
).The documentation explains it this way:
https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-in-docker-executor
As I understand it,
docker run
will delegate the command to thedocker:dind
service. That service will spawn anopenjdk
container. In turn, Testcontainers will use the Docker daemon ofdocker:dind
through the/var/run/docker.sock
binding.In conclusion, this configuration is over-complicated, because the
docker
container does nothing but delegating its work todocker:dind
.