Because networks are not specified, docker-compose will create project network, which defaults to bridge mode.
The docker references can be a little bit confusing. So let me try to clear that up:
By setting DOCKER_TLS_CERTDIR to empty, the dind instance is forced to use plain TCP
The runner connects to dind over TCP.
The docker.sock referenced in the register-runner is in reference to the dind executor. It’s how the containers in the docker container can talk to docker.
This config runs fully in dind.
This config is based on a config that I found and then optimized (and brought up to docker 20).
The config in the repo does some filesystem caching.
I was struggling for hours in order to have a full gitlab ci/cd-> docker-compose runner configuration up and running with no luck till now.
At a certain point it was clear to me that i needed to configure a dind service for my docker runner but i was unable to make it work correctly.
Now i ran your docker-compose and its working like a charm!
Thanks man!
Great work, @ TyIsI
However, I’m not able to start the dind container:
ip: can't find device 'ip_tables'
ip_tables 36864 0
x_tables 53248 12 xt_state,xt_ipvs,xt_nat,xt_policy,xt_mark,xt_u32,xt_tcpudp,xt_conntrack,xt_MASQUERADE,xt_addrtype,nft_compat,ip_tables
modprobe: can't change directory to '/lib/modules': No such file or directory
mount: permission denied (are you root?)
Could not mount /sys/kernel/security.
AppArmor detection and --privileged mode might break.
mount: permission denied (are you root?)
What do you see in the dind logging? (docker-compose logs -f dind)
The errors you see are because of the way that Docker normally works. (It sets up NAT with IP tables to allow incoming traffic to containers. However, as this is not required for dind, it’s safe to ignore this.)
However, the “dind” service keeps dying and the register-runner repeats indefinitely starting/registering/dying cycles. The limit of 50 registered runners is reached, but no runner gets online.
i didnot get the gitlab-runner to run in the qnap container. I get the following error message:
Runtime platform arch=amd64 os=linux pid=7 revision=456e3482 version=15.10.0
Starting multi-runner from /etc/gitlab-runner/config.toml… builds=0
Running in system-mode.
WARNING: There might be a problem with your config
jsonschema: ‘/runners’ does not validate with https://gitlab.com/gitlab-org/gitlab-runner/common/config#/$ref/properties/runners/type: expected array, but got null
Created missing unique system ID system_id=r_OqExoOxwLG52
Configuration loaded builds=0
listen_address not defined, metrics & debug endpoints disabled builds=0
[session_server].listen_address not defined, session endpoints disabled builds=0
Initializing executor providers builds=0
ERROR: Failed to load config stat /etc/gitlab-runner/config.toml: no such file or directory builds=0
just tried this and I’m encountering a few issues:
How do I inject the proper DNS server using the docker-compose.yml ? for some reason our DNS is not working inside the runner container
error "fatal: unable to access '/associates/myProject.git/': Could not resolve host: mygitlab.host.com"
At work we have a MITM proxy, which means every docker container must spin up with our rootCA added to the update-ca-certificates (cp /etc/gitlab-runner/ca-certificates.crt /usr/local/share/ca-certificates/ && update-ca-certificates) the proper rootCA (ca-certificates.crt) is in the config subfolder when doing docker compose up -d
error " **x509: certificate signed by unknown authority**"
“No such image” error due to reaching the maximum pulls, and not having done a docker login. Should I add a docker login to the docker-compose.yml ??
ERROR: Preparation failed: Error: No such image:
Would be nice if the docker-compose also did the gitlab-runner unregister --name “runner-name” , each time we compose down
so according to this , it is necessary to specify helper_image: in the config.toml to override the default helper_image that doesn’t seem to work. Can it really be this complicated?
I have confirmed this works by execing into the container and adding that value to the runners.docker in the config.toml. So how do I edit the docker-compose.yml to inject this into the config.toml ?
Here’s my recommendation for enhancing your GitLab Runner setup with the latest best practices:
Key Improvements
Latest Images: Using latest stable releases of Docker and GitLab Runner for security and features
Enforced TLS: Fully secured with TLS certificates for all Docker communications
Intelligent Auto-Registration: Runner only registers when needed, preventing duplicates
Health Checks: DinD health check ensures the Docker engine is fully operational before runner connects (see advance-docker-compose)
Default Parameters: Added sensible defaults for environment variables with override capability
Volume Management: Dedicated Docker volume for better performance and data persistence
This setup offers the optimal balance of security, performance, and maintainability. The TLS implementation protects against unauthorized access to your Docker daemon, while the conditional registration script efficiently manages runner configuration.
Let me know if you need any adjustments to match your specific environment requirements.
Thank you @mrioux for your scripts. I have set up my GitLab runner with your advance-docker-compose.yml example. The only change I have from your docker-compose.yml is I added --docker-network-mode=host to the end of the gitlab-runner register script so that it could find the DNS record for our self-hosted GitLab instance.
I’ve been trying to set up a new docker build job with the following in my .gitlab-ci.yml.
When the job runner runs this job, I get the following error final lines in my log output:
$ echo "Building Docker image..."
Building Docker image...
$ docker info
Failed to initialize: unable to resolve docker endpoint: open /certs/client/ca.pem: no such file or directory
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
Also if I leave off the docker-build-job variables my log output ends:
$ echo "Building Docker image..."
Building Docker image...
$ docker info
Client:
Version: 28.3.2
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.26.1
Path: /usr/local/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.39.1
Path: /usr/local/libexec/docker/cli-plugins/docker-compose
Server:
error during connect: Get "http://docker:2375/v1.51/info": dial tcp: lookup docker on 127.0.0.11:53: server misbehaving
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1
Do you have any insights on why the certs would not be available to the docker image in my docker-build-job and how to successfully connect back to the dind?