Gitlab Kubernetes runner with Docker in Docker

Contents
Docker in Docker (DIND) is a powerful tool for running Docker containers within Docker containers. This allows developers to easily create and test Docker images within a container environment that closely resembles the production environment. This can help to catch issues early in the development process and ensure that the application is running as expected in the production environment
DinD config for kubernetes runner
All examples stored in repo
Register and deployGitlab Runner
- Create new runner in Gitlab UI [USER] > [REPO] > [CI/CD Settings] > [New runner].
Save
<token>
, and assign tags (for exampledind
to use it later) - Deploy the runner to k8s
kubectl create ns gitlab helm repo add gitlab https://charts.gitlab.io/ helm repo update helm upgrade -i gitlab-runner \ --set gitlabUrl=https://gitlab.com,runnerRegistrationToken=<token> \ gitlab/gitlab-runner \ -n gitlab \ -f values.yaml
Gitlab job manifest
Gitlab needs additional variables like DOCKER_HOST
, DOCKER_TLS_CERTDIR
, see working example below
docker-compose:
image: docker:latest
stage: test
services:
- docker:dind
variables:
# Enable log output for service container
CI_DEBUG_SERVICES: "true"
# Instruct Testcontainers to use the daemon of DinD, use port 2375 for non-tls connections.
DOCKER_HOST: "tcp://docker:2375"
# Improve performance with overlayfs.
DOCKER_DRIVER: "overlay2"
# Instruct Docker not to start over TLS.
DOCKER_TLS_CERTDIR: ""
script:
- |
docker-compose up
tags:
- dind