Ayush Pallav
Ayush Pallav

Reputation: 1057

Not able to build docker image in gitlab CI

Been trying to build a simple gitlab CI pipeline which builds an image and pushes it to Google container repository. I am running through this error -

ERROR: error during connect: Get "http://docker:2375/v1.24/info": dial tcp: lookup docker on 169.254.169.254:53: no such host

I have tried all the solutions posted across gitlab issues threads but no help. I am using public runners, it's a pretty simple ci script.

image: docker:latest

variables:
  GCR_IMAGE: <GCR_IMAGE>

services:
  - docker:dind

build:
  stage: build
  before_script:
    - docker info
    - echo $GOOGLE_CLOUD_ACCOUNT | docker login -u _json_key --password-stdin https://us.gcr.io
  script:
    - docker build -t $GCR_IMAGE:latest .
    - docker push $GCR_IMAGE:$CI_COMMIT_SHA

Relevant issue thread: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4794

Using gitlab-runner 15.7.1

Upvotes: 3

Views: 10710

Answers (2)

Matrix Matrix
Matrix Matrix

Reputation: 1

If you have error with ce.pam you can disable TSL:

DOCKER_TLS_VERIFY: 0

Upvotes: -1

xirehat
xirehat

Reputation: 1689

A few weeks ago I encountered this problem and was able to solve it with this method:

  image: 
    name: docker:20.10.16
  services:
    - name: docker:20.10.16-dind
  variables:
    DOCKER_HOST: tcp://docker:2376/
    DOCKER_TLS_CERTDIR: "/certs"
    DOCKER_TLS_VERIFY: 1
    DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
  before_script:
    - until docker info; do sleep 1; done
    - echo $GOOGLE_CLOUD_ACCOUNT | docker login -u _json_key --password-stdin https://us.gcr.io
  script:
    - docker build -t $GCR_IMAGE:latest .
    - docker push $GCR_IMAGE:$CI_COMMIT_SHA

Also add this configuration to runner

    [[runners]]
      [runners.kubernetes]
        namespace = "{{.Release.Namespace}}"
        image = "ubuntu:20.04"
      [[runners.kubernetes.volumes.empty_dir]]
        name = "docker-certs"
        mount_path = "/certs/client"
        medium = "Memory"

Upvotes: 5

Related Questions