Can't register Gitlab Runner via docker (compose)

Describe your question in as much detail as possible:
I have self-managed Gitlab on my localhost.
I’m trying to register Gitlab Runner through Docker. Here is my docker-compose.yml

version: "3.0"

services:
  web:
    image: 'gitlab/gitlab-ce:latest'
    restart: always
    hostname: 'gitlab.my.test'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'https://gitlab.my.test'
        letsencrypt['enable'] = false
        # Add any other gitlab.rb configuration here, each on its own line
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
    volumes:
      - './export/containers/gitlab/config:/etc/gitlab'
      - './export/containers/gitlab/logs:/var/log/gitlab'
      - './export/containers/gitlab/data:/var/opt/gitlab'
  gitlab-runner:
    image: gitlab/gitlab-runner:latest
    container_name: gitlab-runner
    restart: always
    depends_on:
      - web
    volumes:
      - ./export/containers/gitlab-runner/config:/etc/gitlab-runner
      - ./export/containers/gitlab-runner/var/run/docker.sock:/var/run/docker.sock
  • What are you seeing, and how does that differ from what you expect to see?
    I use docker run --rm -it -v /my-path/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register and expect the runner to be registered, but I get:
ERROR: Registering runner... failed                 runner=UVjXdea- status=couldn't execute POST against https://gitlab.my.test/api/v4/runners: Post https://gitlab.my.test/api/v4/runners: dial tcp: lookup gitlab.my.test on 192.168.0.1:53: no such host
PANIC: Failed to register the runner. You may be having network problems.

I am interested in this exact same topic. In particular, I would very much like to see a gitlab repo with everything ready to go - just docker-compose up and off to the races.

Special consideration: in my case I want to be able to build projects that involve building and running containers - so docker in docker.

I’ve found a solution. The problem was because of networks. You should create a network in your docker-compose like this:

networks:
  gitlab:

And assign the containers to this network. Then when you are going to register a runner, use --network=gitlab so all containers will be in the same network. In my case:

run --rm -it --network=gitlab -v /my-path/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register