Docker login to AWS ECR from GitLab CI fails with "dial tcp: lookup docker on x.x.x.x:53: no such host" when pulling docker:dind from ECR

13,041

Solution 1

To resolve this problem just add on /etc/gitlab-runner/config.toml a volume map to docker sock.

volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]

Solution 2

When building docker image in gitlab-ci, you must add this (dind is for "docker in docker"):

services:
  - docker:dind
Share:
13,041
Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I'm working on porting a collection of Docker images used for GitLab CI/CD building and deployment from Dockerhub to AWS public ECR. Everything works as it should except for the standard Docker image that we use as a Docker-in-Docker service. The same exact image that works when pulled from Dockerhub fails to login when pulled from public ECR.

    .gitlab-ci.yml

        build-push:
          stage: package
          image: public.ecr.aws/x/x
          services:
          - public.ecr.aws/x/docker-dind:20.10
    
    $ aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_DOCKER_REGISTRY_URL
    > Logging in to Docker registry...
    > error during connect: Post http://docker:2375/v1.24/auth: dial tcp: lookup docker on 8.8.8.8:53: no such host
    
    $ cat /etc/hosts
    127.0.0.1   localhost
    ::1 localhost ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    172.17.0.2  public.ecr.aws__*
    172.17.0.2  public.ecr.aws-*
    172.17.0.3  runner-*
    

    Thank you.

    • Admin
      Admin about 3 years
      This looks like a DNS or networking issue in (could be both) in your build container.
    • Admin
      Admin about 3 years
      It looks like it’s resolving the name docker (from http://docker:2375/v1.24/auth URL) through 8.8.8.8 Google nameserver.
    • Admin
      Admin over 2 years
      Did you find the solution for this? I am facing the same error.
  • Orbán Zoltán
    Orbán Zoltán over 2 years
    And if you need network,. than add "privileged=true" to the /etc/gitlab-runner/config.toml
  • zar3bski
    zar3bski over 2 years
    Isn't 127.0.0.1 or am I missing something?