繁体   English   中英

在本地运行 GitLab 和 GitLab-Runner docker 实例时,管道中的构建步骤因连接被拒绝错误而失败

[英]Build step in pipeline is failing with connection refused error while running GitLab and GitLab-Runner docker instances locally

我在本地运行 GitLab 和 Gitlab-Runner docker 实例。 执行 Spring Boot 和 Maven 项目管道时,出现以下错误。

Getting source from Git repository
00:02
 Fetching changes with git depth set to 50...
 Reinitialized existing Git repository in /builds/root/starter-springboot-pipeline/.git/
 fatal: unable to access 'http://localhost/root/starter-springboot-pipeline.git/': Failed to connect to localhost port 80: Connection refused
Uploading artifacts for failed job
00:07
 ERROR: Job failed: exit code 1

不确定上述错误中的 localhost 是指 GitLab 容器还是 Runner 容器。 它应该引用 gitlab 容器而不是本地主机吗?

以下是我使用的命令和配置。

启动 GitLab 服务器:

docker run -itd --network=gitlab-network --hostname localhost \
           --publish 443:443 --publish 80:80 --publish 22:22 \
           --name gitlab --restart always --volume config:/etc/gitlab \
           --volume logs:/var/log/gitlab \
           --volume data:/var/opt/gitlab \
           gitlab/gitlab-ee:12.10.14-ee.0

启动 GitLab Runner

docker run -d --name gitlab-runner --restart always \
     -v ~/gitlab/gitlab-runner/config:/etc/gitlab-runner \
     -v /var/run/docker.sock:/var/run/docker.sock \
     gitlab/gitlab-runner:v12.10.3

创建了网络“gitlab-network”并将两个容器都添加到其中。

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

注册Runner如下:

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://gitlab
Please enter the gitlab-ci token for this runner:
XxXXxXXXxxXXXXXX
Please enter the gitlab-ci description for this runner:
[49ad685039ad]: runner14
Please enter the gitlab-ci tags for this runner (comma separated):
docker
Registering runner... succeeded                     runner=EkWnb63h
Please enter the executor: docker-ssh, parallels, shell, virtualbox, docker+machine, kubernetes, custom, docker, ssh, docker-ssh+machine:
docker
Please enter the default Docker image (e.g. ruby:2.6):
alpine:latest
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

下面是 gitlab-ci.yml

image: maven:3.3-jdk-8
stages:
  - test
  
test_job:
  stage: test
  script:
    - pwd
    - mvn clean
    - mvn compile
    - mvn test
  tags:
    - docker

我刚刚开始研究 GitLab 和 docker,能够在通过大量研究解决一些问题后设置它们并运行管道。 但我被这个问题困住了。

主机名localhost始终解析为127.0.0.1::1 - 换句话说,就是回送接口,顾名思义,它会循环回并连接到自身。

这意味着您的跑步者正试图在自己的容器中找到http://localhost/root/starter-springboot-pipeline.git/ - 这显然失败了,因为它在 GitLab 的容器中。

这也是为什么在您的运行器配置中,您必须将 GitLab 的地址指定为http://gitlab而不是http://localhost

您可以尝试使用命令启动 GitLab 容器(预先重新创建命名卷以确保它是从头开始配置的)

docker run -itd --network=gitlab-network --hostname gitlab \
           --publish 443:443 --publish 80:80 --publish 22:22 \
           --name gitlab --restart always \
           --env GITLAB_OMNIBUS_CONFIG="external_url 'http://gitlab/'" \
           --volume config:/etc/gitlab \
           --volume logs:/var/log/gitlab \
           --volume data:/var/opt/gitlab \
           gitlab/gitlab-ee:12.10.14-ee.0

但我不能保证它会起作用,因为 GitLab 旨在运行在具有自己唯一主机名的服务器上。

编辑:

您也可以尝试编辑config.toml并将[runners.docker]部分中的network_mode设置为gitlab-network 请参阅此处了解更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM