Gitlab CI/CD job failed due to dial tcp: lookup docker on 169.254.169.254:53: no such host

I have .gitlab-ci.yml configuration like this:

image: docker:stable

cache:
  key: $CI_COMMIT_REF_SLUG
  paths:
    - node_modules/

services:
  - docker:24.0.5-dind

variables:
  DOCKER_DRIVER: overlay
  SPRING_PROFILES_ACTIVE: gitlab-ci
  MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"

stages:
  - build
  - package
  - deploy
  - deploy_prod

docker-build:
  stage: package
  script:
    - docker build -t registry.gitlab.com/erensimsek/web-ui:$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA .
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD registry.gitlab.com
    - docker push registry.gitlab.com/erensimsek/web-ui:$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA


When I try to run stages, I’m getting error like this:

$ docker build -t registry.gitlab.com/erensimsek/web-ui:$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA .
error during connect: Post http://docker:2375/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=r048dz518x72v4dw821szh77g&shmsize=0&t=registry.gitlab.com%2Ferensimsek%2Fweb-ui%3Amain-50d88598&target=&ulimits=null&version=1: dial tcp: lookup docker on 169.254.169.254:53: no such host

Thanks for taking the time to be thorough in your request, it really helps! :blush: