gitlab-cigitlab-ci-runnerdocker-in-dockergitlab-autodevops

Gitlab Auto Deploy failing to connect to Docker


I've got Gitlab installed on Kubernetes using Helm and try to get Auto DevOps working but I'm getting the following issue from the Auto DevOps pipeline:

Executing "step_script" stage of the job script 00:01
$ 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

I've read abt the issues with Docker-in-Docker, but I couldn't get it to work.

I also tried setting the DOCKER_HOST: tcp://docker:2375/ variable, but I still get the same error.

Cannot connect to the Docker daemon at tcp://docker:2375/. Is the docker daemon running?

My Gitlab Runner Helm values looks like this:

gitlabUrl: https://gitlab.mydomain.com
privileged: true
rbac:
  create: true
runnerRegistrationToken: mytoken
runners:
  config: |
    [[runners]]
      executor = "docker"
      privileged = true
      environment = ["DOCKER_TLS_CERTDIR="]
      [runners.docker]
        tls_verify = false
        privileged = true

I tried using the Auto-DevOps .gitlab-ci.yml template.

My cluster is integrated into Gitlab using the cluster certificate method and running simple CI/CD like

test_project:
  stage: test
  script:
  - npm run test

Works fine

I tried docker:18.09.7, docker:19.03.1 and docker:latest (and the corresponding -dind services, with or without setting DOCKER_HOST: tcp://docker:2375/)

I don't know what I'm missing.


Solution

  • // Update

    I got this issue resolved with help from the Gitlab Support. My issue was that I had to use [runners.kubernetes] config and set privileged to true there. I was only setting it in [runners.docker] as I thought that Kubernetes Gitlab Runners would that config.