Docker build image service fails

I’m having an issue with a docker build image, the intention is to use it to build docker images for use as runners, ansible etc. The issue I’m having is that even a very simple deployment fails with service unavailable.

Here is the pipeline definition

stages:
  - build

docker_build:
  stage: build
  image: docker:latest
  services:
    - docker:dind
  script:
    - docker info

And here is the output

Running on runner-zqec-bjs-project-44882169-concurrent-0cm7qk via kube-runner-gitlab-runner-77fbc58bf9-fp2hm...
Getting source from Git repository
00:02
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/silvacloudsystems/aqua-container-build/.git/
Created fresh repository.
Checking out 3dba9ffe as detached HEAD (ref is main)...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:01
$ docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.8.2)
  compose: Docker Compose (Docker Inc., v2.6.0)
Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: command terminated with exit code 1

I’ve tried different runners, docker-based, Kubernetes based and shared, with the same results. I’ve tried with and without the service set, with the host and port variables set and it’s the same basic issue.
Does anyone have any thoughts about what might be causing the issue or a better way to perform the same function.

The issue is around “Docker in Docker” dind, which requires specific configuration on either s docker of Kubernetes based runner. When using shared runners the tag “docker” with insure that the job is run on a host configured for dind. Below is a configuration that works for using dind with shared runners.

docker_build:
  stage: build
  image:
    name: docker:latest
  services:
    - docker:dind
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build -t $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME/deb-runner:latest .
    - docker push $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME/deb-runner:latest
  tags:
    - docker

Hi Everyone,

I am still running into similar issue.

docker-build:
  stage: docker
  variables: 
    DOCKER_DRIVER: overlay2
    DOCKER_HOST: tcp://docker:2376
    DOCKER_TLS_CERTDIR: "/certs"
    DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
    GIT_DEPTH: 0

  image:
    name: docker:latest
  services:
    - docker:dind

  before_script:
    - apk add docker
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY 
  script:
    - docker build -t $APP_IMAGE .
    - docker run -d -p 8090:8080 $APP_IMAGE
  tags:
    - docker
$ stat /var/run/docker.sock

[79](/jobs/#L79) File: /var/run/docker.sock

[80](/jobs/#L80) Size: 4096 Blocks: 8 IO Block: 4096 directory

[81](/jobs/#L81)Device: fd00h/64768d Inode: 929264 Links: 2

[82](/jobs/#L82)Access: (0777/drwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)

[83](/jobs/#L83)Access: 2023-07-10 19:11:17.865294788 +0000

[84](/jobs/#L84)Modify: 2023-07-10 19:11:17.865294788 +0000

[85](/jobs/#L85)Change: 2023-07-10 19:11:17.865294788 +0000

[86](/jobs/#L86)$ docker version

[87](/jobs/#L87)Client:

[88](/jobs/#L88) Version: 24.0.3

[89](/jobs/#L89) API version: 1.43

[90](/jobs/#L90) Go version: go1.20.5

[91](/jobs/#L91) Git commit: 3713ee1

[92](/jobs/#L92) Built: Wed Jul 5 20:43:45 2023

[93](/jobs/#L93) OS/Arch: linux/amd64

[94](/jobs/#L94) Context: default

[95](/jobs/#L95)Cannot connect to the Docker daemon at tcp://docker:2376. Is the docker daemon running?