Socket error when

building a docker image with dind in a gitlab-runner on kubernetes fails with ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Pipeline results:

Running with gitlab-runner 17.4.0 (b92ee590)
on gitlab-runner-86ccfd4c4f-n98jg L-6q8LiSC, system ID: r_DPOse9seCSRW
Preparing the "kubernetes" executor
Using Kubernetes namespace: gitlab
Using Kubernetes executor with image docker ...
Using attach strategy to execute scripts...
Preparing environment
Using FF_USE_POD_ACTIVE_DEADLINE_SECONDS, the Pod activeDeadlineSeconds will be set to the job timeout: 1h0m0s...
Waiting for pod gitlab/runner-l-6q8lisc-project-28-concurrent-0-321y075e to be running, status is Pending
Waiting for pod gitlab/runner-l-6q8lisc-project-28-concurrent-0-321y075e to be running, status is Pending
ContainersNotReady: "containers with unready status: [build helper svc-0]"
ContainersNotReady: "containers with unready status: [build helper svc-0]"
Running on runner-l-6q8lisc-project-28-concurrent-0-321y075e via gitlab-runner-86ccfd4c4f-n98jg...
Getting source from Git repository
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/devops/test-app/.git/
Created fresh repository.
Checking out 323324d9 as detached HEAD (ref is main)...
Skipping Git submodules setup
Executing "step_script" stage of the job script
$ docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cleaning up project directory and file based variables
ERROR: Job failed: command terminated with exit code 1'

Steps to reproduce

values.yaml

gitlabUrl: <server>
concurrent: 5
logFormat: json
rbac:
  create: true
serviceAccount:
  create: true
runners:
  config: |
    [[runners]]
      [runners.kubernetes]
        privileged = true
runnerToken: <token>

.gitlab-ci.yml:

stages:
- build

build_image:
stage: build
image: docker
services:
  - docker:dind
script:
  - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .
  - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA

Versions:

  • GitLab GitLab Enterprise Edition [v17.4.1-ee] self hosted
  • GitLab Runner: gitlab-runner 17.4.0