Error during connect: Post http://docker:2375/v1.40/auth: dial tcp: lookup docker on 169.254.169.254:53: no such host

I was having this issue and I follow the suggestion of @a.mashukov, now I’m getting a similar message but in the build stage.

my .gitlab-ci.yml:
# Official docker image.

image: docker:latest

services:

  - docker:dind

before_script:

  - echo "$CI_REGISTRY"

  - echo "$CI_REGISTRY_USER"

  - echo "$CI_REGISTRY_PASSWORD"

  - echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY --username $CI_REGISTRY_USER --password-stdin

Building image:

  stage: build

  tags:

    - build

    - docker

    - test

  script:

    - docker build --pull -t "$CI_REGISTRY_IMAGE"/my-image .

only:
  - master

And the output of the job:

`Checking out 2d606f0a as master...` `Skipping Git submodules setup ` `$ echo "$CI_REGISTRY"  ` `registry.gitlab.com` `$ echo "$CI_REGISTRY_USER"` `gitlab-ci-token` `$ echo "$CI_REGISTRY_PASSWORD"` `[MASKED]` `$ echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY --username $CI_REGISTRY_USER --password-stdin` `WARNING! Your password will be stored unencrypted in /root/.docker/config.json.` `Configure a credential helper to remove this warning. See` `https://docs.docker.com/engine/reference/commandline/login/#credentials-store` `Login Succeeded` `$ echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY --username $CI_REGISTRY_USER --password-stdin` `WARNING! Your password will be stored unencrypted in /root/.docker/config.json.` `Configure a credential helper to remove this warning. See` `https://docs.docker.com/engine/reference/commandline/login/#credentials-store` `Login Succeeded` `$ docker build --pull -t "$CI_REGISTRY_IMAGE"/staging/aruba-autos.com --build-arg DB_ROOT_PASSWORD=xt-d3f4ultp455w0rd --build-arg DB_NAME=aruba-autos.com --build-arg DOMAIN=staging.aruba-autos.com --build-arg THEME_REPOSITORY=git@gitlab.com:xenotrue/development/osclass_them_xt-curacaoproperties.git --build-arg SITE_ROOT_EXTRAS=git@gitlab.com:xenotrue/infrastructure/xt-web-solution-backups/curacao-properties.com/curacao-properties.com_site-root_extras.git --build-arg THEME_IMAGES=git@gitlab.com:xenotrue/infrastructure/xt-web-solution-backups/curacao-properties.com/curacao-properties.com_them_imag_uploads.git --build-arg UPLOADS_REPOSITORY=git@gitlab.com:xenotrue/infrastructure/xt-web-solution-backups/curacao-properties.com/curacao-properties.com_oc-content_uploads.git --build-arg PLUGIN_BANNERS=git@gitlab.com:xenotrue/development/osclass_plug_xt-banners.git --build-arg BANNERS_IMAGES=git@gitlab.com:xenotrue/infrastructure/xt-web-solution-backups/curacao-autos.com/curacao-autos.com_plug_bann_banners.git --build-arg PLUGIN_PACKAGES=git@gitlab.com:xenotrue/development/osclass_plug_xt-packages.git --build-arg PLUGIN_SOCIAL=git@gitlab.com:xenotrue/development/osclass_plug_social-bookmarks.git --build-arg PLUGIN_YOUTUBE=git@gitlab.com:xenotrue/development/osclass_plug_youtube.git --build-arg PLUGIN_PAYPRO=git@gitlab.com:xenotrue/development/osclas_payments-pro.git --build-arg INFRASTRUCTURE_SSH_PRIVATE_KEY="$INFRASTRUCTURE_SSH_PRIVATE_KEY" .` `Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?` `ERROR: Job failed: exit code 1`

Any help?