GitLab Runner 错误:准备失败:守护程序的错误响应:仅用户定义网络中的容器支持网络范围的别名

问题描述 投票:0回答:1

我正在尝试使用 GitLab Runner 设置 GitLab CI/CD 管道,并且需要能够将我的主机网络与容器一起使用,而不是默认的桥接网络。因此,我将“network_mode =”host”添加到我的 GitLab Runner 的 config.toml 文件中。

我已经为我的项目设置了一个 docker-compose.yml 文件,该文件在我的本地电脑上运行良好。但是,构建总是失败并出现以下错误:

Running with gitlab-runner 16.6.1
  on DevOpsCourseRunner AcswPCaLi
Preparing the "docker" executor
00:03
Using Docker executor with image ubuntu:latest ...
Pulling docker image ubuntu:latest ...
Using docker image sha256:e4c58958181a5925816faa528ce959e487632f4cfd192f8132f71b32df2744b4 for ubuntu:latest with digest ubuntu@sha256:2b7412e6465c3c7fc5bb21d3e6f1917c167358449fecac8176c6e496e5c1f05f ...
Preparing environment
00:00
ERROR: Job failed (system failure): prepare environment: Error response from daemon: network-scoped alias is supported only for containers in user defined networks (exec.go:78:0s). Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information

这是我的 .gitlab-ci.yml 文件(我使用 docker run hello-world 来测试管道是否正常工作,并确保问题不在于我的 docker-compose.yml 文件):

stages:
  - build
  - test
  - deploy

before_script:
  - docker-compose --version
  - docker --version

build_job:
  stage: build
  services:
    - docker:dind
  tags:
    - build
    - docker
  script:
    - echo "Building the application..."
    - docker run --network host hello-world
  only:
    - project

我的本地电脑操作系统是Windows 11,GitLab Runner是Linux。

知道如何修复这个错误吗?

docker gitlab gitlab-ci gitlab-ci-runner
1个回答
0
投票

可能是因为您正在使用

services: docker:dind

这会尝试在运行器容器和服务容器之间创建链接。并且

network_mode=host
不支持链接。

© www.soinside.com 2019 - 2024. All rights reserved.