When trying to use the Docker CLI in a GitLab pipeline job, the pipeline fails with the error:
error during connect: Post http://docker:2375/v1.24/auth: dial tcp: lookup docker on 169.254.169.254:53: no such host
This can be caused by several reasons but the most common reason is due to a missing Docker Service that needs to be run in the pipeline alongside the Docker CLI.
There is an extra service that needs to be added to the
.gitlab-ci.yml which enables the GitLab CI to use the Docker CLI.
Add the service Docker Image. by adding this to your yml script:
services: - docker:19.03.12-dind
.gitlab-ci.yml will now look like this and your GitLab pipeline should now work:
docker-push: stage: push image: docker:latest services: - docker:19.03.12-dind script: - docker login --username jaykc --password "$DOCKER_ACCESS_KEY" - docker build -t <<REPOSITORY ID>>/<<IMAGE NAME>>:1.0 . - docker push <<REPOSITORY ID>>/<<IMAGE NAME>>:1.0