Gitlab-ci with dockerized gitlab-runner

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:   /var/lib/gitlab-runner   nfs    auto  0  0
sudo mount -a

Start gitlab-runner with spawning capabilities:


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 \

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 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.
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:
Please enter the default Docker image (eg. ruby:2.1):
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:

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_timeout = 1800

  name = "kostbevakningen-runner"
  url = ""
  token = "******"
  executor = "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
    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 or it will use some random runner with ruby.
  • Also need to check Run untagged jobs:

Update 2020

Another update. I needed another runner for another group in gitlab. Noticed that it didn't work to use the registration token directly in the config.toml. So better run a temp container to register:

docker run --rm -t -i -v /var/lib/gitlab-runner/woodenstake:/etc/gitlab-runner gitlab/gitlab-runner register

Enter the token from gitlab web there. This will generate the toml but the token there will be a new one.

Go in and edit the generated toml with proper settings.

Then start with something like:

    image: gitlab/gitlab-runner:latest
    container_name: gitlab-runner-kb
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/gitlab-runner/kostbevakningen:/etc/gitlab-runner
    restart: unless-stopped
    image: gitlab/gitlab-runner:latest
    container_name: gitlab-runner-ws
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/gitlab-runner/woodenstake:/etc/gitlab-runner
    restart: unless-stopped

Update 2023

Now I'm running a k3s cluster on PI4's and there are Helm charts like so:

## Add gitlab charts repo
    helm repo add gitlab
    helm repo update gitlab
## Create namespace
    k apply -f TAKE4-2023/k3s/gitlab-runners/gitlab.yaml 
    helm install --namespace gitlab gitlab-runner-kb gitlab/gitlab-runner

   helm install --namespace gitlab gitlab-runner-kb gitlab/gitlab-runner

   helm upgrade gitlab-runner-kb \
        --set gitlabUrl=,runnerRegistrationToken=glrt-__MYTOKEN__ \
        gitlab/gitlab-runner -n gitlab