docker-compose - `unable to access ' XXX ': Could not resolve host` Gitlab CI/CD 管道

标签 docker-compose gitlab continuous-delivery

我们将 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

中docker执行器配置下的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 restartgitlab-runner restart 重新启动 gitlab runner

关于docker-compose - `unable to access ' XXX ': Could not resolve host` Gitlab CI/CD 管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64452521/

相关文章:

docker - 即使从 BIOS 设置启用虚拟化后,也无法在 Windows 10 Home 上运行 Docker Toolbox

gitlab - 构建后的测试将在 gitlab-ci 的新环境中运行

Jenkins 2 Pipelines - 如何为持续交付管道建模

docker - CI/CD使影像保持最新状态

docker - Windows 10 docker-compose 占用 100% 的磁盘使用率

docker - docker容器中的redis服务数据如何存储

node.js - docker 撰写 : NodeJS + MongoDB

docker - Gitlab DOCKER_AUTH_CONFIG 不起作用

node.js - NPM 安装导致 401 Unauthorized for private repo

GitLab CI 手动启 Action 业(部署)