user971741
user971741

Reputation:

no such host error while doing docker build from gitlab CI

I am trying to build CI pipeline to build and publish my application docker image, however during build i am getting following error:

.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

However, this gets me following error:

$ 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

Any idea, whats the issue here?

Upvotes: 10

Views: 17072

Answers (3)

rrauenza
rrauenza

Reputation: 6963

I had this issue and it was because we pull our image from an internal proxy. When you do that, the name isn't "docker". To fix, add an alias:

services:
    - name: harbor.example.com/dockerhub-proxy-cache/library/docker:24.0.7-dind
      alias: docker

Reference: https://docs.gitlab.com/ee/ci/services/#accessing-the-services

Upvotes: 6

slavny_coder
slavny_coder

Reputation: 170

Update your /etc/gitlab-runner/config.toml file.

[runners.docker]
    tls_verify = false
    image = "ruby:2.7"
    privileged = true <- change this from false to true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"] <- provide path to docker.sock
    shm_size = 0

Upvotes: 4

sytech
sytech

Reputation: 40861

You are missing the docker:dind service.

The image you should use for the job is the normal docker:latest image.

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

Upvotes: 9

Related Questions