Install gitlab-runner

1
2
3
4
docker run -d --name <your_runner_name> --restart always \
  -v /path/to/config:/etc/gitlab-runner \
  -v /var/run/docker.sock:/var/run/docker.sock \
  gitlab/gitlab-runner:latest

Register to your GitLab

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
docker exec -it <your_runner_name> gitlab-runner register \
  --non-interactive \
  --url "http://<your_gitlab.com>/ci" \
  --registration-token "zZDBGW3cdoZBFY2ifYkt" \
  --executor "docker" \
  --docker-image alpine:3 \
  --description "<your_runner_name>" \
  --tag-list "<runner_tag1>,<runner_tag2>..." \
  --run-untagged \
  --locked="false"

Enable dind services

vi /path/to/config/config.toml
or
docker exec -it pbd-ubuntu-shared-runner vi /etc/gitlab-runner/config.toml

modify volumes = ["/cache"] to volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
concurrent = 1
check_interval = 0

[[runners]]
  name = "##"
  url = "http://##.##/ci"
  token = "##"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "alpine:3"
    privileged = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    shm_size = 0
  [runners.cache]

PS : I don’t know why volumes must be modified, tell me why if someone known it. I found this solution from here.

After that, you can use services dind in .gitlab-ci.yml

1
2
services: 
  - docker:dind

Reference