Cannot connect to the Docker daemon at tcp://localhost:2375

Cannot connect to the Docker daemon at tcp://localhost:2375
Gitlab CI Build failing
Getting source from Git repository
00:02
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/docker/php/.git/
Created fresh repository.
Checking out 2ef777e8 as 8.0...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:02
$ if [[ -z "$CI_COMMIT_TAG" ]]; then # collapsed multi-line command
$ /build/build.sh
Logging in to GitLab Container Registry with CI credentials...
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
Building Dockerfile-based application...
Attempting to pull a previously built image for use with --cache-from...
Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?
Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?
No previously cached image found. The docker build will proceed without using a cached image
Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?
Cleaning up file based variables
00:00
ERROR: Job failed: command terminated with exit code 1

Add this to your .gitlab-ci.yml

services:
  docker:dind

Basic Gitlab AutoDevOps Example - .gitlab-ci.yml


image: alpine:latest                                                                                                                            
                                                                                                                                                
services:                                                                                                                                       
  - docker:dind                                                                                                                                 
                                                                                                                                                
variables:                                                                                                                                      
  # KUBE_INGRESS_BASE_DOMAIN is the application deployment domain and should be set as a variable at the group or project level.                
  KUBE_INGRESS_BASE_DOMAIN: domain.example.com                                                                                                  
                                                                                                                                                
  DOCKER_DRIVER: overlay2                                                                                                                       
                                                                                                                                                
  ROLLOUT_RESOURCE_TYPE: deployment                                                                                                             
                                                                                                                                                
  DOCKER_TLS_CERTDIR: ""  # https://gitlab.com/gitlab-org/gitlab-runner/issues/4501                                                             
                                                                                                                                                
stages:                                                                                                                                         
  - build                                                                                                                                       
                                                                                                                                                
include:                                                                                                                                        
  - template: Jobs/Build.gitlab-ci.yml  # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml