Found out that I needed to include the docker socket in the gitlab-runner configuration as well, and not only have it available in the container. By adding --docker-volumes '/var/run/docker.sock:/var/run/docker.sock' and removing DOCKER_HOST=tcp://docker:2375 I was able to connect to docker on my host system and spawn sibling containers.

Answer from Roberto on Stack Overflow
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › use ci/cd to build your application › jobs › docker › use docker to build docker images
Use Docker to build Docker images | GitLab Docs
You can use GitLab CI/CD with Docker to build, test, and push container images. To run Docker commands in CI/CD jobs, you must configure GitLab Runner to support docker commands.
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › use ci/cd to build your application › jobs › docker › run ci/cd jobs in docker containers
Run your CI/CD jobs in Docker containers | GitLab Docs
Register a runner and configure it to use the Docker executor. Specify the container image where you want to run the CI/CD jobs in the .gitlab-ci.yml file.
Discussions

linux - Deploy docker container using gitlab ci docker-in-docker setup - Stack Overflow
I'm currently trying to setup a gitlab ci pipeline. I've chosen to go with the Docker-in-Docker setup. I got my ci pipeline to build and push the docker image to the registry of gitlab but I cannot... More on stackoverflow.com
🌐 stackoverflow.com
Docker build with Gitlab CI/CD
For gitlab ci you'll want to install a runner. Then, populate your repo with a .gitlab-ci.yml file which defines your docker build. https://docs.gitlab.com/ee/ci/runners https://docs.gitlab.com/ee/ci/docker/using_docker_build.html Found an example .gitlab-ci.yml file with Google. https://gist.githubusercontent.com/florentchauveau/2dc4da0299d42258606fc3b0e148fc07/raw/86fd64c514364800209180ec78d2704070a3c7b6/.gitlab-ci.yml More on reddit.com
🌐 r/docker
8
26
March 4, 2021
GitLab Runner in Docker
I’d suggest setting up your runners using the docker executor - https://docs.gitlab.com/runner/executors/docker.html This allows your runner to start up fresh containers for jobs with the image you specify, meaning jobs aren’t running on the host and can have whatever you need. You can then also use a single runner with parallelism instead of multiple runners. Downside is that if you need to install extras they will need to install as part of the CI on every job. More on reddit.com
🌐 r/gitlab
6
3
August 31, 2023
CI/CD Dilemma for Python Project: To go for Docker in Docker or not?
Maybe I'm missing something here, but what you're describing doesn't sound too different from what we're doing, and it doesn't require DinD. For running commands inside a shell in the container you just built, you can just define a variable with the image name (we use something combining CI_REGISTRY_IMAGE and CI_COMMIT_SHORT_SHA) and use it in the image: statement for the job. For running integration tests against the image, look into the services: keyword. You can define a custom name under which the container will be DNS resolvable from your job. If needed, you can also override the entrypoint. That approach doesn't offer quite the full flexibility of DinD, but for us it covers most use cases while avoiding the drawbacks. Edit: to clarify, this all works using the Docker runner. However, if you need to test more complex deployments, e.g. using docker-compose, go for DinD. It's not that much of a hassle to set up. More on reddit.com
🌐 r/gitlab
10
8
February 20, 2022
🌐
Medium
medium.com › @tonywooster › docker-in-docker-in-gitlab-runners-220caeb708ca
Docker-in-Docker in Gitlab Runners | by Tony Wooster | Medium
January 31, 2018 - Any use of docker inside of the build containers should either create auto-named containers, or manually utilize ${CI_BUILD_REF} to disambiguate them. This won’t work for docker-compose use, however, since all potentially simultaneous builds of a project will have the same COMPOSE_PROJECT_NAME. You can either set this manually, or automatically for all Docker runners by editing your /srv/gitlab-runner/config.toml file:
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › use ci/cd to build your application › jobs › docker
Docker integration | GitLab Docs
For example, use a Node image from Docker Hub so your job runs in a container with all the Node dependencies you need.
🌐
Python⇒Speed
pythonspeed.com › articles › gitlab-build-docker-image
Building Docker images on GitLab CI: Docker-in-Docker and Podman
January 22, 2025 - DOCKER_TLS_CERTDIR: "" script: # GitLab has a built-in Docker image registry, whose # parameters are set automatically. You can use some # other Docker registry though by changing the login and # image name. - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY" - docker build -t "$CI_REGISTRY_IMAGE:dind" .
Find elsewhere
🌐
Reddit
reddit.com › r/docker › docker build with gitlab ci/cd
r/docker on Reddit: Docker build with Gitlab CI/CD
March 4, 2021 -

Hey cool docker cats, I have a hopefully common problem that I’ve not been able to locate any resources to help me along.

I have a python repo that supports other repos. Currently in the subsequent repo build pipelines I install the python file to be used as part of the test pipeline for the repo. Ideally, I want to build a docker image after each successful git commit pipeline to the main python supporting utility. Then use that newly created image as the base image in my other repo pipelines for subsequent tests related to the given repo.

Hopefully clear, can you point to any helpful resources or walk me through an example? This seems super basic in my head but haven’t connected the dots.

Cheers

🌐
Medium
medium.com › @BuildWithLal › dockerized-gitlab-ci-docker-executor-as-a-docker-in-docker-docker-dind-b8557759e557
Dockerized GitLab CI: Docker Executor as a Docker in Docker (docker:dind) | by Lal Zada | Medium
October 13, 2024 - It will access it by using Server ... from neworking? lets jump into the runner registeration part · Go to Repository → Settings → CI/CD → Runners...
🌐
GitLab
docs.gitlab.com › gitlab docs › administer › administer gitlab runner › runner executors › docker
Docker executor | GitLab Docs
The Docker executor uses Docker Engine to run each job in a separate and isolated container. To connect to Docker Engine, the executor uses: The image and services you define in .gitlab-ci.yml.
🌐
DevOps.dev
blog.devops.dev › containerized-ci-cd-gitlab-pipelines-with-docker-runners-03b9411088ee
Containerized CI/CD: GitLab Pipelines with Docker Runners | by Kusuma Ningrat | DevOps.dev
June 13, 2025 - Runner executes jobs in Docker containers based on specific images (eg. docker-in-docker) ... Docker-in-Docker allows your CI jobs (inside a Docker container) to run Docker commands themselves — such as docker build, docker run, docker push, etc.
🌐
Reddit
reddit.com › r/gitlab › gitlab runner in docker
r/gitlab on Reddit: GitLab Runner in Docker
August 31, 2023 -

Hi all,

We recently moved to GitLab, and I am tasked with setting up the testing stuff for our pipeline.

We had gitlab runners recently installed on our server, but I am running into some problems. I’m new to all this, so while reading documentation has been helpful, I’m still unsure on a lot of things.

The Gitlab-Runner is installed and registered on 3 separate docker containers in the server (so 3 runners total)

The docker containers use the official docker alpine gitlab runner image

The Gitlab-Runner is in shell executor mode

When I run my script through gitlab-ci, I am getting command not found for sudo, apt, node, npm, docker, etc.

From what i can tell, that’s because the runner is running the CI script directly in the docker container from the official images, which do not have any of these installed.

So even if I switch from shell executor to docker executor, this would not work since the official runner image doesn’t have docker installed correct?

Is the correct path here to start docker containers with gitlab runners registered in it, but the docker container itself needs to be docker in docker? Is the official gitlab runner alpine image able to run in docker in docker?

🌐
TestDriven.io
testdriven.io › blog › gitlab-ci-docker
Deploying Self-Hosted GitLab CI Runners with Docker | TestDriven.io
October 29, 2021 - Follow the official installation ... Next, you'll need to obtain a registration token and URL. Within your group's "CI/CD Settings", expand the "Runners" section....
🌐
Docker
docs.docker.com › manuals › docker scout › integrations › continuous integration › integrate docker scout with gitlab ci/cd
Integrate Docker Scout with GitLab CI/CD | Docker Docs
November 26, 2024 - Add the following to a .gitlab-ci.yml file at the root of your repository. docker-build: image: docker:latest stage: build services: - docker:dind before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY # Install curl and the Docker Scout CLI - | apk add --update curl curl -sSfL https://raw.githubusercontent.com/docker/scout-cli/main/install.sh | sh -s -- apk del curl rm -rf /var/cache/apk/* # Login to Docker Hub required for Docker Scout CLI - echo "$DOCKER_HUB_PAT" | docker login -u "$DOCKER_HUB_USER" --password-stdin
🌐
DEV Community
dev.to › arbythecoder › introduction-to-docker-integration-in-gitlab-cicd-pipelines-4lg6
Introduction to Docker Integration in GitLab CI/CD Pipelines - DEV Community
June 14, 2024 - Create a .gitlab-ci.yml file in your project directory with the following content: stages: - build - push variables: DOCKER_DRIVER: overlay2 IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG build_image: stage: build image: docker:latest services: - docker:dind script: - docker build -t $IMAGE_TAG .
🌐
Reddit
reddit.com › r/gitlab › ci/cd dilemma for python project: to go for docker in docker or not?
r/gitlab on Reddit: CI/CD Dilemma for Python Project: To go for Docker in Docker or not?
February 20, 2022 -

Hi.

I'm trying to create a ci/cd pipeline for our teams, which each develop a certain ML microservice which is containrized in a docker image. Our gitlab is selfhosted and we also have a dedicated server which is supposed to host the runner.

From what I've found out till now, in the CI/CD pipeline, we should:

  1. For a merge request:

    1. Unit Test the developed software.

    2. Check the quality of code.

  2. After a couple of merges, create a release branch:

    1. Acceptance tests.

    2. Deploy to staging

  3. After each commit in the release branch:

    1. Update the staging.

  4. Merge to master:

    1. Deploy to production.

We also use a very well defined python environment for our images, and that isolated environment almost never changes considerably. (The base image is labelled as `myrepo/custom_python_image` for example).

So playing by gitlab there seems to be 2 options:

  1. Using docker in docker in the CI pipeline. In this way I can unit test in the GitLab runner container.

  2. Using shell for my CI pipeline. In this way I have to migrate the tests inside my built docker container.

The problem with docker in docker was that I could not cache pulled images, (or large binaries), and hence made it slow.

  1. Is there anyway to make DinD work for image caches?

  2. Does it worth the hassle?

  3. Is there any alternative to DinD or shell at all?

Thanks!

P.S: If the question was a bit unclear, sorry for that. English is not my first language so my writing my come as disjointed.

Top answer
1 of 6
5
Maybe I'm missing something here, but what you're describing doesn't sound too different from what we're doing, and it doesn't require DinD. For running commands inside a shell in the container you just built, you can just define a variable with the image name (we use something combining CI_REGISTRY_IMAGE and CI_COMMIT_SHORT_SHA) and use it in the image: statement for the job. For running integration tests against the image, look into the services: keyword. You can define a custom name under which the container will be DNS resolvable from your job. If needed, you can also override the entrypoint. That approach doesn't offer quite the full flexibility of DinD, but for us it covers most use cases while avoiding the drawbacks. Edit: to clarify, this all works using the Docker runner. However, if you need to test more complex deployments, e.g. using docker-compose, go for DinD. It's not that much of a hassle to set up.
2 of 6
4
You want to use docker runners. Then you can use your build image with your build dependencies preinstalled. Docker in docker is only really needed if you want to build a docker image in the pipeline, and even then you could use something like kaniko instead. Regarding caching, you might want to cache your application's dependencies themselves. This depends a bit on what tech stack you're using, but likely you can configure the package manager's cache directory to be inside your project directory in conjunction with using GitLab CI's cache feature. Another option is to use a local package proxy, like Sonatype Nexus.
🌐
Medium
medium.com › swlh › gitlab-ci-docker-an-unorthodox-but-hopefully-useful-workflow-29a4149c8acb
GitLab CI & Docker — An Unorthodox (but hopefully useful) Workflow | by Nathan Otenti | The Startup | Medium
December 18, 2019 - The env job is responsible for building the environment that the build and test will run in. The publish job take artifacts from the build job and packages them in a Docker container for use in deployment. The env job is configured within a Docker container itself. To see how GitLab CI handles Docker-in-a-Docker (dind), have a look here.
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
How to run docker CLI in the in a Container - GitLab CI/CD - GitLab Forum
December 16, 2019 - Hi All, I’m trying to run docker CLI in a container and connecting it to the Docker daemon on the host. I have register the gitlab runner to use docker and share /var/run/docker.sock and use the docker image in the .git…
🌐
Medium
medium.com › devops-with-valentine › how-to-start-a-docker-container-inside-your-gitlab-ci-pipeline-bfeb610c3f4
How to Start a Docker Container Inside your GitLab CI Pipeline | by Valentin Despa | DevOps with Valentine | Medium
September 21, 2023 - package where the application is dockerized, and the image is being pushed to the GitLab Container Registry. For your reference, this is how the .gitlab-ci.yml looks like this at this stage: