You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker部署GitLab Runner执行Job报错:无法解析docker主机

GitLab Runner Docker Executor 连接失败排查

问题场景

我在服务器上通过Docker执行以下命令注册GitLab Runner:

docker exec -it gitlab-runner gitlab-runner register \
--non-interactive \
--url "http://gitlab.aloghesti.local" \
--registration-token "glrt-v5YDsxuazYRUXMXRsuWU" \
--executor "docker" \
--docker-image docker:latest \
--docker-tlsverify="false" \
--docker-privileged="false" \
--docker-volumes='/var/run/docker.sock:/var/run/docker.sock' \
--docker-volumes='/cache' \
--description "aloghesti-runner" \
--tag-list "docker.sock,imac" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"

但每次执行Job时都会出现如下错误:

Running with gitlab-runner 16.5.0 (853330f9)
  on aloghesti-runner v5YDsxuaz, system ID: r_qfj6n9LoVjcy
Preparing the "docker" executor
ERROR: Failed to remove network for build
ERROR: Preparation failed: error during connect: Get "http://docker:2375/v1.24/info": dial tcp: lookup docker on 8.8.8.8:53: no such host (docker.go:826:0s)
Will be retried in 3s ...
ERROR: Failed to remove network for build
ERROR: Preparation failed: error during connect: Get "http://docker:2375/v1.24/info": dial tcp: lookup docker on 8.8.8.8:53: no such host (docker.go:826:0s)
Will be retried in 3s ...
ERROR: Failed to remove network for build
ERROR: Preparation failed: error during connect: Get "http://docker:2375/v1.24/info": dial tcp: lookup docker on 8.8.8.8:53: no such host (docker.go:826:0s)
Will be retried in 3s ...
ERROR: Job failed (system failure): error during connect: Get "http://docker:2375/v1.24/info": dial tcp: lookup docker on 8.8.8.8:53: no such host (docker.go:826:0s)

已在谷歌等渠道大量搜索解决方案,但仍未找到问题所在,恳请协助排查。

排查与解决步骤

1. 核心问题分析

错误提示中的http://docker:2375/v1.24/info表明,GitLab Runner的Docker executor默认尝试连接docker:2375主机,但DNS解析失败。尽管你已经挂载了/var/run/docker.sock,但Runner配置中未明确指定Docker主机地址,导致它没有使用socket通信。

2. 修改Runner配置文件

找到GitLab Runner的配置文件(容器内路径通常为/etc/gitlab-runner/config.toml,如果宿主机有挂载目录,直接修改宿主机对应文件即可),定位到对应runner的[runners.docker]区块,添加或修改以下配置:

[runners.docker]
  # 保留原有其他配置
  host = "unix:///var/run/docker.sock"
  tls_verify = false

3. 重启Runner容器

配置修改完成后,重启GitLab Runner容器使配置生效:

docker restart gitlab-runner

4. 验证连接(可选)

进入Runner容器,测试Docker连接是否正常:

docker exec -it gitlab-runner docker info

若能正常输出Docker系统信息,说明socket连接已正常工作。

5. 额外检查项

  • 确认宿主机/var/run/docker.sock的权限设置正确,Runner容器内的用户需要具备访问该socket的权限(可临时执行chmod 666 /var/run/docker.sock测试,后续再调整更安全的权限配置)
  • 通过docker inspect gitlab-runner命令检查容器是否正确挂载了/var/run/docker.sock
  • 若使用Docker-in-Docker模式才需要开启privileged,你当前设置为false符合socket挂载的场景,无需修改

内容的提问来源于stack exchange,提问作者Ahmad Badpey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 20:22:44