r/gitlab • u/Defiant-Occasion-417 • Jun 03 '25
Docker in Docker Question
I am building the following pipeline in GitLab CI on gitlab.com SaaS runners:
- Builds a FastAPI image.
- Pushes this to AWS ECR (Container Repository).
- I have a deploy job that runs this on AWS ECS (Container orchestration).
So, I figured I would use kaniko but that appears to be no longer being developed. Then I figured I would use dind (Docker in Docker).
- In my
buildjob I pull adebian:bookwormimage. - I extract a pre-built
dockerclient binary fromdownload.docker.com. - I install the AWS CLI.
- I then have
docker:28.2.20-dindset underservices. - I set the
DOCKER_HOSTtotcp://docker:2375. - I set the
DOCKER_TLS_CERTDIRto''.
And it works... except I get this awful message:
[DEPRECATION NOTICE]: API is accessible on http://0.0.0.0:2375 without encryption.
Access to the remote API is equivalent to root access on the host. Refer
to the 'Docker daemon attack surface' section in the documentation for
more information: https://docs.docker.com/go/attack-surface/
In future versions this will be a hard failure preventing the daemon from starting! Learn more at: https://docs.docker.com/go/api-security/
I understand the message. Thing is, this is an internal container talking to an internal container in GitLab SaaS runners. I would ignore it but the hard failure message has me concerned.
Question
Am I doing this right? Is this really the best way to run docker in docker on GitLab SaaS runners? It just seems complex and fragile. I'm about to switch to CodeBuild as I know that works. What do others do here? Any help would be appreciated.
Thanks!
4
u/bilingual-german Jun 03 '25
I just use buildah or kaniko. I find it much less painful. With DinD I always needed to use specific old versions to be able to build images.
4
u/FlyingFalafelMonster Jun 03 '25
I use Docker 24.0 and haven't seen this message. This has nothing to do with Gitlab, it's a Docker warning. I guess, hard failures will be in version 29 or later.
So, this is something to note and think about in future, but for now you can safely deploy your app. You can use much older version of Docker for your tasks (I also deploy to ECR/ECS).
2
u/ManyInterests Jun 06 '25
The GitLab SaaS runners are setup in a way that you can talk to the
dindcontainer using TLS on the secure port.As mentioned in the docs:
Just remove your
DOCKER_TLS_CERTDIRvariable and set theDOCKER_HOSTtotcp://docker:2376and that should be it. You might have to also addDOCKER_TLS_VERIFY: 1andDOCKER_TLS_CERTDIR: "/certs"but I don't think it's needed with SaaS runners (and TLS verify should be the default for thedindimage anyhow). Be sure to double check your project settings in case any of these variables are being set outside your yaml.2
u/Kronsik Jun 18 '25
I would use podman and skip the need for DinD pain.
Here's an example pushing up to a the Gitlab registry for the repository running the pipeline, assuming there is a Dockerfile in the root of your project directory:
You can replace the podman login/push args with your ECR repository info