如何解决连接到在 Gitlab docker executor 中启动的 docker 容器
我们有一个带有 Sysbox (link to the setup) 的 Gitlab 设置,以避免在特权模式下运行 docker 执行程序。目前,services
属性有效,我们可以与其通信,但无法访问以 dind
开头的容器。这是重现问题的最小 .gitlab-ci.yml
文件:
docker_gitlab_test:
stage: test
image: docker:19.03.13
tags:
- docker # this is our docker executor
services:
- docker:19.03.12-dind
script:
- apk add curl
- mkdir test
- echo "hello world" > test/index.html
- docker run -d -p 8080:80 -v $(pwd)/test:/usr/share/nginx/html:ro --hostname nginx --name nginx nginx
- curl localhost:8080
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
curl 命令返回 curl: (7) Failed to connect to localhost port 8080: Connection refused
。运行 nmap
表示所有端口都已关闭。我知道此设置适用于 privileged
docker executors。我尝试在 --privileged
命令上设置 docker run
但无济于事。我尝试过除 docker
以外的其他基本映像,但问题仍然存在。我试过运行 nginx
以外的图像,但发生了同样的问题。
如何允许 gitlab 作业访问在 dind
上分离运行的容器?
解决方法
您可以尝试用 0.0.0.0
代替 localhost
吗?此外,跑步者的 network_mode
属性应为 host
(https://docs.gitlab.com/runner/executors/docker.html)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。