Multiple containers for multiple Runners

  • What version are you on? Are you using self-managed or GitLab.com?

    • GitLab: 15.7.7
    • Runner: 15.11.0. Self-managed.
  • What are you seeing, and how does that differ from what you expect to see?

I am trying to set up a server to host multiple runners for my team’s GitLab projects. I’ve followed the guide so I took these steps:

docker volume create gitlab-runner-config

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

docker exec -it projectA gitlab-runner register

Like that, it works completely fine, but I want to add multiple containers so that each one of them hosts the runner for one of the projects. So I run the same command again, with a different name:

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

docker exec -it projectB gitlab-runner register

As they share the same volume, they share the config.toml file. If I run gitlab-runner list in one of the containers, both runners are shown.

After creating the second container, it stopped working, this is the error:

I tried creating a different docker volume but it doesn’t work either. I guess by the error that it has something to do with both runners sharing /var/run/docker.sock.

I’ve searched the forum and the only similar thing I’ve found is this. Following that I believe we can solve the problem using only one gitlab-runner in a container, and registering all of the runners in that one. But that’s not the solution we are seeking, we want the runners to be independent. Is there a way of solving this error mantaining the structure of a volume containing several containers, one for each runner?

Thank you!

You should not share the config file between two runners. Each runner must have a different token. You must create a separate config for every runner, and connect/register them in gitlab.

But that is not the problem here. I’m getting the same errors as you (docker socket not available).