2

On self hosted Gitlab on GCP installed by helm, I use Gitlab-runner.

On gitlab-runner I need to use docker so using dind, but I got error

tcp://docker:2375. Is the docker daemon running?

gitlab-runner deployment

...
    spec:
      containers:
      - command:
        - /bin/bash
        - /scripts/entrypoint
        env:
        - name: CI_SERVER_URL
          value: https://my-gitlab.com
        - name: CLONE_URL
        - name: RUNNER_REQUEST_CONCURRENCY
          value: "1"
        - name: RUNNER_EXECUTOR
          value: kubernetes
        - name: REGISTER_LOCKED
          value: "false"
        - name: RUNNER_TAG_LIST
        - name: KUBERNETES_IMAGE
        - name: KUBERNETES_PRIVILEGED
          value: "true" # <= set privileged true to use dind
...

gitlab-ci.yaml

services:
  - docker:20.10.4-dind

stages:
    - build

variables:
    GIT_SSL_NO_VERIFY: "1"    
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ''
    DOCKER_HOST: tcp://docker:2375

image:
    name: google/cloud-sdk:latest
before_script:
  - docker version

build:
  stage: build
  script:
    - echo hello

gitlab-runner log

Executing "step_script" stage of the job script
00:00
$ docker version
Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?
Client: Docker Engine - Community
 Version:           19.03.11
 API version:       1.40
 Go version:        go1.13.10
 Git commit:        42e35e61f3
 Built:             Mon Jun  1 09:09:53 2020
 OS/Arch:           linux/amd64
 Experimental:      false
Cleaning up file based variables
00:00
ERROR: Job failed: command terminated with exit code 1

troubleshooting says that it's because of TLS. So I set DOCKER_TLS_CERTDIR: '' , the way written in another document.

Also, this problem didn't happen when I used docker:19.03.0-dind. From 19.03.0-dind, TLS is automatically. So disable TLS configuration must be worked correctly. (docker:19.3.13-dind also worked well.)

I don't know why from docker:20 this error showed up. Has anyone already tried gitlab-runner with grater than docker:20 ?

Ryo
  • 485
  • 1
  • 8
  • 26

1 Answers1

3

I figured out that I should follow https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#docker-in-docker-with-tls-enabled-in-kubernetes

toml

runners:
  config: |
    [[runners]]
      [runners.kubernetes]
        image = "ubuntu:20.04"
        privileged = true
      [[runners.kubernetes.volumes.empty_dir]]
        name = "docker-certs"
        mount_path = "/certs/client"
        medium = "Memory"

gitlab-ci.yaml

services:
  - docker:20.10.4-dind

stages:
    - build

variables:
    GIT_SSL_NO_VERIFY: "1"    
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: "/certs" 
    DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"    
    DOCKER_HOST: tcp://docker:2376
    DOCKER_TLS_VERIFY: 1
    
image:
    name: google/cloud-sdk:latest
before_script:
  - docker version

build:
  stage: build
  script:
    - echo hello
Ryo
  • 485
  • 1
  • 8
  • 26