如何解决在本地运行GitLab和GitLab-Runner Docker实例时,管道中的构建步骤因连接拒绝错误而失败
我正在本地运行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容器而不是localhost吗?
下面是我使用的命令和配置。
启动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
注册跑步者如下:
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进行工作,能够解决大量研究工作中的一些问题,从而能够设置它们并运行管道。但是我一直坚持这个问题。
解决方法
主机名mov rax,1 ; write(
mov rdi,1 ; STDOUT_FILENO,mov rsi,msg ; "Hello,world!\n",mov rdx,msg_len ; sizeof("Hello,world!\n")
syscall ; );
始终解析为localhost
或127.0.0.1
-换句话说,是回送接口,顾名思义,该接口回送并连接到iteslf。
这意味着您的跑步者正试图在自己的容器中找到::1
-显然失败了,因为它在GitLab的容器中。
这也是为什么在运行程序配置中必须将GitLab的地址指定为http://localhost/root/starter-springboot-pipeline.git/
而不是http://gitlab
您可以尝试使用命令启动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
并将config.toml
部分中的network_mode
设置为[runners.docker]
。有关更多信息,请参见here。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。