Install Gitlab runner as a docker container

Mount a share from NAS

First click a NFS share on the NAS, then

sudo mkdir /var/lib/gitlab-runner

In /etc/fstab, add:

10.0.1.30:/raiden/gitlab-runner   /var/lib/gitlab-runner   nfs    auto  0  0
sudo mount -a

Start gitlab-runner with spawning capabilities:

From https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/348b700b137f3ef1b7ca4e5890d79774a9632b72/docs/install/docker.md

mkdir /var/lib/gitlab-runner/config

sudo docker run -d --name gitlab-runner --restart always \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /var/lib/gitlab-runner/config:/etc/gitlab-runner \
  gitlab/gitlab-runner:latest

docker docker.sock mount is to be able to spawn runner.

Setup the runner:

sudo docker exec -it gitlab-runner gitlab-runner register --docker-privileged

Here you get a lot of questions.
In my case I'm using https://gitlab.com/ci as the coordinator URI. The token you get from your projects page. I wasn't sure what to do with the else, but realized later.

So, I'm going to use gitlab/dind to be my runner.

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci):
https://gitlab.com/ci
Please enter the gitlab-ci token for this runner:
*****************
Please enter the gitlab-ci description for this runner:
[22ee90a98372]: ensime-atom-docker
Please enter the gitlab-ci tags for this runner (comma separated):
main, dind
Registering runner... succeeded                     runner=******_
Please enter the executor: docker+machine, docker-ssh+machine, docker, docker-ssh, parallels, shell, ssh, virtualbox:
docker
Please enter the default Docker image (eg. ruby:2.1):
gitlab/dind:latest
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

Here was the thing: I couldn't do a non-interactive registration

After this, I can go to my project at:

https://gitlab.com/hedefalk/ensime-atom-docker/runners

And I'll see this runner. I'll disable shared runners so I'm sure this one is used.

Update 2018:

The way I did docker in docker (dind) dind image was old and I couldn't use it for multi-stage docker builds. So I needed to update the config to simply use the official docker:stable:

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "kostbevakningen-runner"
  url = "https://gitlab.com/"
  token = "******"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "docker:stable"
    privileged = true
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    shm_size = 0
  [runners.cache]
    Insecure = false

Killed off old stuff and ran with:

    sudo docker run -d --name gitlab-runner-kb --restart always -v /var/lib/gitlab-runner/kostbevakningen:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
  • Also need to turn off shared runners per project in gitlab.com or it will use some random runner with ruby.
  • Also need to check Run untagged jobs: