自定义Gitlab跑步者失败 - 无法连接到Docker守护程序

发布于 2025-02-02 21:58:43 字数 2082 浏览 1 评论 0 原文

这些是我遵循的步骤来设置自定义的GitLab跑步者:

  1. 通过在此处按照说明来安装GitLab Runner: https://docs.gitlab.com/runner/install/linux-repository.html

  2. 注册 docker exectuor和 docker的跑步者:19 image> image> image

  3. gitlab-ci.yml 如下:

image: docker:19.03.1

services:
  - name: docker:19.03.1-dind
    alias: docker

stages:
- build

build:
  stage: build
  variables:
    IMAGE_TAG: repo.azurecr.io/some-repo
    DOCKER_HOST: tcp://172.17.0.1:2375
    DOCKER_TLS_CERTDIR: ''
  script:
    - docker login someacr.azurecr.io -u "$SERVICE_PRINCIPAL_USER" -p "$SERVICE_PRINCIPAL_PASSWORD"
    - if [[ "$CI_COMMIT_REF_NAME" == "develop" ]]; then docker build -t $IMAGE_TAG .; fi
  1. 运行管道引发以下错误:
Login succeeded
if [[ "$CI_COMMIT_REF_NAME" == "develop" ]]; then docker build -t $IMAGE_TAG .; fi
Cannot connect to the Docker daemon at tcp://172.17.0.1:2375. Is the docker daemon running?
Cleaning up project directory and file based variables
00:02
ERROR: Job failed: exit code 1

这是我到目前为止尝试的:

  1. 特权:true in /etc/gitlab -runner/config.toml
  2. dind:19 docker Image gitlab-ci.yml
  3. 添加卷= [“/var/run/run/docker)。 sock/var/run/docker.sock“”“/cache”] in /etc/gitlab-runner/config.toml
  4. 使用 docker_tls_certdir:'' in' in gitlab-ci.yml 作为变量
  5. docker_host 带有 docker_host的变量:tcp://172.17.0.1.1:2375
  6. 更多...

填充 更改导致GitLab Runner在此处进行故障排除的两个问题中的任何一个:

  1. docker:无法连接到tcp:// docker:2375。 Docker守护程序在运行吗?
  2. Docker没有这样的主机错误。

These are the steps I followed to setup a custom Gitlab runner:

  1. Install Gitlab runner by following the instructions here: https://docs.gitlab.com/runner/install/linux-repository.html

  2. Register a runner with docker exectuor and docker:19 image

  3. Write gitlab-ci.yml as follow:

image: docker:19.03.1

services:
  - name: docker:19.03.1-dind
    alias: docker

stages:
- build

build:
  stage: build
  variables:
    IMAGE_TAG: repo.azurecr.io/some-repo
    DOCKER_HOST: tcp://172.17.0.1:2375
    DOCKER_TLS_CERTDIR: ''
  script:
    - docker login someacr.azurecr.io -u "$SERVICE_PRINCIPAL_USER" -p "$SERVICE_PRINCIPAL_PASSWORD"
    - if [[ "$CI_COMMIT_REF_NAME" == "develop" ]]; then docker build -t $IMAGE_TAG .; fi
  1. Running the pipeline throws this error:
Login succeeded
if [[ "$CI_COMMIT_REF_NAME" == "develop" ]]; then docker build -t $IMAGE_TAG .; fi
Cannot connect to the Docker daemon at tcp://172.17.0.1:2375. Is the docker daemon running?
Cleaning up project directory and file based variables
00:02
ERROR: Job failed: exit code 1

This is what I have tried so far:

  1. privileged: true in /etc/gitlab-runner/config.toml
  2. dind:19 docker image in gitlab-ci.yml
  3. adding volumes = ["/var/run/docker.sock /var/run/docker.sock" "/cache"] in /etc/gitlab-runner/config.toml
  4. used DOCKER_TLS_CERTDIR: '' in gitlab-ci.yml as variable
  5. populating DOCKER_HOST variable with DOCKER_HOST: tcp://172.17.0.1:2375
  6. much more...

All these changes result in either of the 2 issues described in Gitlab Runner Troubleshooting here: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#troubleshooting

  1. docker: Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?
  2. Docker no such host error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北陌 2025-02-09 21:58:43

您的 docker_host 变量值不正确。

使用 Docker_host:“ TCP:// Docker:2375”

添加卷= [“/var/run/docker.sock/var/run/docker.sock”“/cache”]

添加卷= [“ /var/run/docker.sock/var/run/docker.sock”“/cache var/run/docker.sock 在此处的跑步者配置。当利用 docker:dind 服务容器方法时,这不是必需的。但是,从技术上讲,它不会引起问题。

特权:true in /etc/gitlab-runner/config.toml
[...]
使用的docker_tls_certdir:''在gitlab-ci.yml中为变量

这些更改很好,请继续进行这些更改。

Your DOCKER_HOST variable value is not correct.

Use DOCKER_HOST: "tcp://docker:2375"

adding volumes = ["/var/run/docker.sock /var/run/docker.sock" "/cache"] in /etc/gitlab-runner/config.toml

I would recommend removing the volume mount of /var/run/docker.sock from the runner configuration here. This is not necessary when leveraging the docker:dind service container method. Though, it technically won't cause issues.

privileged: true in /etc/gitlab-runner/config.toml
[...]
used DOCKER_TLS_CERTDIR: '' in gitlab-ci.yml as variable

These changes are good, keep these changes.

咿呀咿呀哟 2025-02-09 21:58:43

为了使Docker:Dind在Gitlab CI中遇到最小问题,必须正确设置四个参数:

  • 应该设置服务“ Docker:20.10.16-Dind”或更高版本。
  • Docker_tls_certdir变量应设置为“”,否则似乎试图使用TLS。
  • docker_host变量应设置为“ tcp:// docker:2375”
  • ,ff_network_per_build应该设置为true。它允许Docker服务和所使用的图像之间进行通信。

示例部分.gitlab-ci.yml文件将是:

variables: 
  DOCKER_DIND: "docker:20.10.16-dind"                                                          
  DOCKER_TLS_CERTDIR: ""
  DOCKER_HOST: "tcp://docker:2375"
  FF_NETWORK_PER_BUILD: "true"

job_name:
  image: julienlecomte/docker-make
  services:                                                                                   
    - $DOCKER_DIND                                                                            
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

In order to have the least issues with docker:dind within a gitlab ci, four parameters have to be correctly set:

  • The service should be set 'docker:20.10.16-dind' or later.
  • DOCKER_TLS_CERTDIR variable should be set to "" otherwise it seems it tries to use TLS.
  • DOCKER_HOST variable should be set "tcp://docker:2375"
  • And FF_NETWORK_PER_BUILD should be set to true. It allows communication between the docker service and image used.

A sample partial .gitlab-ci.yml file would be:

variables: 
  DOCKER_DIND: "docker:20.10.16-dind"                                                          
  DOCKER_TLS_CERTDIR: ""
  DOCKER_HOST: "tcp://docker:2375"
  FF_NETWORK_PER_BUILD: "true"

job_name:
  image: julienlecomte/docker-make
  services:                                                                                   
    - $DOCKER_DIND                                                                            
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文