在Docker中将GitLab Runner注册到GitLab

5

我是 Docker 新手。我使用以下命令运行 GitLab CE 容器:

docker run --detach --hostname localhost --publish 443:443 --publish 80:80 --name gitlab --restart always gitlab/gitlab-ce:latest

这个容器运行良好。

我使用以下命令运行gitlab-runner容器:

docker run -d --name gitlab-runner --restart always gitlab/gitlab-runner:latest

我的问题是当我想要注册GitLab Runner时,Runner会询问我:

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):

我对此的回答是:

我回答是:http://localhost:80/,但它给了我一个错误:

ERROR: Registering runner... failed                 runner=K8trLPJx status=couldn't execute POST against http://localhost:80/api/v4/runners: Post http://localhost:80/api/v4/runners: dial tcp 127.0.0.1:80: connect: connection refused
PANIC: Failed to register this runner. Perhaps you are having network problems

我的电脑上有2个容器,使用的是Windows 10操作系统。

我不想在本地计算机上运行gitlab-runner,并且希望使用docker来运行它。

1个回答

3
问题在于两个容器之间缺少网络连接。您可以像这样手动创建它:
docker network create gitlab-network

接下来,使用以下命令让您的容器与其连接:

docker network connect gitlab-network gitlab
docker network connect gitlab-network gitlab-runner

如果容器是可达的,您可以将其作为GitLab-CI协调器URL直接传递gitlab,因为容器的名称就是Docker网络上可达的DNS。

另一个更优雅的解决方案是使用docker-compose同时管理容器和网络。类似于以下内容,我没有测试过:

version: '3.3'

services:
  gitlab:
    image: gitlab/gitlab-ce:latest
    networks:
      - gitlab-network
    ports:
      - 80:80
      - 443:443
    

  gitlab-runner:
    image: gitlab/gitlab-runner:latest
    networks:
      - gitlab-network

networks:
  gitlab-network:

1
Gitlab-runner 的注册不允许直接将 gitlab-ci 协调器 URL 传递为 gitlab。会显示以下错误:仅支持 http 或 https 方案 - Caleb Nasio

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接