简体   繁体   English

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

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

I am running GitLab and Gitlab-Runner docker instances locally.我在本地运行 GitLab 和 Gitlab-Runner docker 实例。 When a Spring Boot and Maven project pipeline is executed, I am getting below error.执行 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

Not sure if the localhost in the above error is referring to GitLab container or Runner container.不确定上述错误中的 localhost 是指 GitLab 容器还是 Runner 容器。 Should it refer to the gitlab container and not the localhost?它应该引用 gitlab 容器而不是本地主机吗?

Below are the commands and configuration I used.以下是我使用的命令和配置。

Start the GitLab server:启动 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

Start the GitLab Runner启动 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

Created Network 'gitlab-network' and added both containers to it.创建了网络“gitlab-network”并将两个容器都添加到其中。

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

Registered the Runner as below:注册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!

Below is the gitlab-ci.yml下面是 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

I have newly started working on GitLab and docker, able to setup them and run the pipeline after resolving some issues with good amount of research.我刚刚开始研究 GitLab 和 docker,能够在通过大量研究解决一些问题后设置它们并运行管道。 But I am stuck with this issue.但我被这个问题困住了。

Hostname localhost is always resolved to 127.0.0.1 or ::1 - in other words to the loopback interface, which as the name suggests loops back and connects to itself.主机名localhost始终解析为127.0.0.1::1 - 换句话说,就是回送接口,顾名思义,它会循环回并连接到自身。

This means that your runner is trying to find http://localhost/root/starter-springboot-pipeline.git/ inside its own container - which obviously fails because it's in GitLab's container.这意味着您的跑步者正试图在自己的容器中找到http://localhost/root/starter-springboot-pipeline.git/ - 这显然失败了,因为它在 GitLab 的容器中。

It's also why, in your runner config, you had to specify GitLab's address as http://gitlab and not as http://localhost这也是为什么在您的运行器配置中,您必须将 GitLab 的地址指定为http://gitlab而不是http://localhost

You might try starting the GitLab container with command (recreate named volumes beforehand to ensure it's configured from scratch)您可以尝试使用命令启动 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

but I can't guarantee it'll work, as GitLab was designed to run on servers that have their own unique hostname.但我不能保证它会起作用,因为 GitLab 旨在运行在具有自己唯一主机名的服务器上。

Edit:编辑:

You may also try editing config.toml and setting network_mode in [runners.docker] section to gitlab-network .您也可以尝试编辑config.toml并将[runners.docker]部分中的network_mode设置为gitlab-network See here for more info.请参阅此处了解更多信息。

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

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