从 gitlab CI 进行 docker 构建时没有这样的主机错误

no such host error while doing docker build from gitlab CI

我正在尝试构建 CI 管道来构建和发布我的应用程序 docker 图像,但是在 build 期间我收到以下错误:

.gitlab-ci.yml:

image: "docker:dind"

before_script:
  - apk add --update python3 py3-pip
  - pip3 install -r requirements.txt
  - python3 --version
...

docker-build:
  stage: Docker
  script:
  - docker build -t "$CI_REGISTRY_IMAGE" .
  - docker ps

但是,这让我出现以下错误:

$ docker build -t "$CI_REGISTRY_IMAGE" .
error during connect: Post "http://docker:2375/v1.24/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=registry.gitlab.com%2Fmaven123%2Frest-api&target=&ulimits=null&version=1": dial tcp: lookup docker on 169.254.169.xxx:53: no such host

知道吗,这里有什么问题?

您缺少 docker:dind 服务。

您应该在作业中使用的图片是正常的 docker:latest 图片。

image: docker
services:
  - "docker:dind"
variables:  # not strictly needed, depending on runner configuration
  DOCKER_HOST: "tcp://docker:2375"
  DOCKER_TLS_CERTDIR: ""