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

amazon-ecramazon-web-servicesdockergitlab

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.

Best Answer

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"]