在Gitlab CI中连接到Docker守护程序的麻烦困难
我正在尝试创建一个相当简单的gitlab ci文件来构建docker映像。每当我运行管道时,我最终都会遇到Docker守护程序连接问题。我该怎么做才能正确构建我的形象?谢谢!
gitlab ci:
image: docker:20.10.16
services:
- docker:20.10.16-dind
variables:
DOCKER_HOST: tcp://docker:2375
iac-build:
stage: build
extends: .iac
rules:
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: always
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
script:
- docker build -t testfirstimage .
allow_failure: false
错误:
$ docker build -t testfirstimage .
failed to dial gRPC: cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: dial tcp 127.0.0.1:2375: connect: connection refused
Cleaning up project directory and file based variables
ERROR: Job failed: command terminated with exit code 1
I'm trying to create a fairly simple GitLab CI file to build out Docker images. Whenever I run the pipeline, I end up getting a Docker daemon connection issue. What can I do to properly build my image? Thanks!
GitLab CI:
image: docker:20.10.16
services:
- docker:20.10.16-dind
variables:
DOCKER_HOST: tcp://docker:2375
iac-build:
stage: build
extends: .iac
rules:
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: always
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
script:
- docker build -t testfirstimage .
allow_failure: false
Error:
$ docker build -t testfirstimage .
failed to dial gRPC: cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: dial tcp 127.0.0.1:2375: connect: connection refused
Cleaning up project directory and file based variables
ERROR: Job failed: command terminated with exit code 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我要检查的第一件事是,您是否已经在该本地主机上运行了一些东西 - 我实际上尝试在本地主机端口上运行服务器数小时,并一直拒绝它,只是发现我忘记了终止我与该端口的连接。
如果不是问题,我以前有这个问题,必须运行此命令才能使其工作:
我花了永远尝试弄清楚它,直到我发现
我没有' t魔术弄清楚了 - 在此问题页面上提出: https:https:https:https:https: //gitlab.com/gitlab-org/gitlab-runner/-/issues/1986
希望这有效。
First thing I would check is if you already have something running on that local host - I've literally tried running a server on a local host port for hours and kept having it refused, only to find out that I had forgotten to terminate my connection to that port.
If that isn't the issue, I had this issue before and had to run this command to get it to work:
I spent forever trying to figure it out and couldn't get anything to work until I found out to add
I didn't figure it out by magic though - props to this issues page: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/1986
Hopefully that works.
为了让Docker-In-In-Docker与Gitlab CI一起工作,您首先需要决定是否要使用或不使用TLS使用Docker-In-in-Docker。然后,更改
/etc/gitlab-runner/config.toml
设置,然后在您的.gitlab-ci.yml
文件中分配docker_tls_tls_certdir
。请参阅 docker in gitlab文档的a>。docker in-docker with tls :
In order to get Docker-in-Docker working with GitLab CI, you will first need to decide if you want to use Docker-in-Docker with or without TLS. Then, change
/etc/gitlab-runner/config.toml
settings, and assign theDOCKER_TLS_CERTDIR
in your.gitlab-ci.yml
file. See the Docker-in-docker section of the GitLab docs.Docker-in-docker with TLS: