我们将 Gitlab 托管在只能通过 L2TP VPN 隧道访问的私有(private)专用服务器上。域的 DNS 设置为内部网络中主机的 IP,因此显然没有 VPN 就无法访问它。问题是,当触发 Gitlab CI/CD 时,作业中会出现错误,日志如下:
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/web/XXX/.git/
fatal: unable to access 'https://<our domain>/web/XXX.git/': Could not resolve host: <our domain>
这里.gitlab-ci.yml
:
图片:docker/compose:最新
services:
- docker:dind
before_script:
- docker version
- docker-compose --version
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
build:
stage: build
script:
- docker-compose --context remote up -d --build
似乎找不到主机的IP。 我什至不知道从哪里开始诊断问题。在托管服务器中,我 ping 主机地址,它显示了正确的 IP 地址。我该如何解决这个问题?
最佳答案
这个错误是因为主机不知道docker。
我也遇到过同样的问题。我已经在config.toml
extra_hosts
参数中添加了域名和域ip
获取您尝试添加的主机的 IP 地址,因为您需要在 extra_hosts
参数中添加主机名和主机 IP。
在您的config.toml
中,进行如下更改:
[[runners]]
name = "maven-docker"
url = "https://<your-domain-name>/gitlab/"
token = "MXvXVma55_Kw2o"
executor = "docker"
[runners.custom_build_dir]
[runners.docker]
tls_verify = false
image = "maven:latest"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
extra_hosts = ["<your-domain-name>:<your-domain-ip>"]
pull_policy = "never"
shm_size = 0
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.custom]
run_exec = ""
然后,使用命令 sudo gitlab-runner restart
或 gitlab-runner restart
重新启动 gitlab runner
关于docker-compose - `unable to access ' XXX ': Could not resolve host` Gitlab CI/CD 管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64452521/