Gitlab Runner Registration Connection Refused

Problem to solve

I’m trying to set up CI/CD for my gitlab instance. I have both gitlab and the gitlab runner in docker containers. I’ve put them both on the same docker network.

When I try to register however, I get an error saying that a TCP connection to the runner’s Docker network IP address was refused.

I hope you’ll forgive me if I’ve missed something obvious. I’m a bit new to the IT/devops side of things.

Steps to reproduce

I’m trying to follow the docker runner installation instructions and the registration instructions.

I’ve gotten as far as to start registering the runner in the gitlab web UI. I logged into the docker container containing the runner, and ran gitlab-runner register, but when I provided the url, it gave me the following error:

ERROR: Verifying runner... failed                   correlation_id=0657a7a65b014254acb69884f971fbdb runner=d0JD84B1Z status=execute JSON request: execute request: couldn't execute POST against http://gitlab/api/v4/runners/verify: Post "http://gitlab/api/v4/runners/verify": dial tcp 172.23.0.3:80: connect: connection refused
PANIC: Failed to verify the runner.

I’ve tried with URLs for both the external name that gets looked up in my router’s DNS, and the internal Docker container name that should use the Docker network’s DNS, but they have the same result. Not sure if it means that the post was refused, or dialing the IP address was refused. If it helps, 172.23.0.3 is the IP of the gitlab-runner docker container.

When looking around stack overflow, I found some people talking about the runner having a docker container inside it, and that it needed to be configured to use the same network as the gitlab container, but since the config file is supposed to be generated as part of registration, I don’t think I’m far enough along for that.

I tried streaming the gitlab logs to a file just to see if there was any reference to the gitlab-runner’s IP or DNS name during a registration request, but there was nothing, so it doesn’t seem like it’s getting that far

Configuration

I don’t have a config.toml yet. This tutorial says that a default one should be created automatically as part of registration.

I made a docker compose file to launch the runner for me:

 services:
    gitlab-runner:
      image: gitlab/gitlab-runner:ubuntu-v18.7.1
      container_name: gitlab-runner
      hostname: <DNS name I configured in my router
      ports:
        - '8093:8093'
      volumes:
        - '$GITLAB_RUNNER_HOME/config:/etc/gitlab-runner'
        - '$GITLAB_RUNNER_HOME/docker-machine-config:/root/.docker/machine'
  networks:
    default:
      external: true
      name: "gitlab"

GITLAB_RUNNER_HOME is configured as /containers/gitlab-runner

For completeness, here’s the compose file for gitlab itself:

services:
  gitlab:
    image: gitlab/gitlab-ee:18.7.0-ee.0
    container_name: gitlab
    restart: always
    hostname: <DNS name I configured in my router>
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        # Add any other gitlab.rb configuration here, each on its own line
        external_url 'http://<the aforementioned DNS name>'
        gitlab_rails['gitlab_shell_ssh_port'] = 50001
        gitlab_rails['initial_root_password'] = <Doesn't matter, I changed it already>
    ports:
      - '50001:22'
    volumes:
      - '$GITLAB_HOME/config:/etc/gitlab'
      - '$GITLAB_HOME/logs:/var/log/gitlab'
      - '$GITLAB_HOME/data:/var/opt/gitlab'
    shm_size: '256m'
networks:
  default:
    external: true
    name: "gitlab"

GITLAB_HOME is configured as /containers/gitlab

For what it’s worth, here’s the part of the docker network json that says all the containers are on the same network:

"Containers": {
            "37fa63cde175d53a1664af3fbd04a74c127d2b2daa1cc906918e2a597fdd624e": {
                "Name": "gitlab-runner",
                "EndpointID": "049121caaff76b0fe0da8e6b3ebf72f2612b96df54e8d7d71093eccc6c673c9d",
                "MacAddress": "da:33:17:ff:c9:47",
                "IPv4Address": "172.23.0.3/16",
                "IPv6Address": ""
            },
            "a2a8f604fbdf621f260cc4db2c49a3d2df11daba78e592c2c6d4b7544628bee0": {
                "Name": "nginx",
                "EndpointID": "6b64997ce2fce006f6543c6a49042a539147c51d324088aad05f443fbbaf95a1",
                "MacAddress": "c6:9e:bd:66:69:4d",
                "IPv4Address": "172.23.0.4/16",
                "IPv6Address": ""
            },
            "a423fe8561c9ab9a8bdcdddd5cee5bd4929a0310cd2467ca68d384d9c44bd434": {
                "Name": "gitlab",
                "EndpointID": "c4b58f36ea8a49986c6489b996a075731cd85cb7b4848b4a9ac32ff00540ba83",
                "MacAddress": "b6:ac:68:09:a8:9b",
                "IPv4Address": "172.23.0.2/16",
                "IPv6Address": ""
            }
        }

Versions

Please select whether options apply, and add the version information.

  • X Self-managed
  • GitLab.com SaaS
  • Dedicated
  • X Self-hosted Runners

Versions

  • GitLab: 18.7.0-ee
  • GitLab Runner: 18.7.1

Seems like the problem was that I didn’t have HTTP_PROXY and HTTPS_PROXY set. Once I set those in the container, it worked like a charm.