Gitlab - Job with "docker in docker" service results in "Cannot connect to the Docker daemon"

10/14/2019

I've added:

services:
 - docker:dind

to my .gitlab-ci.yaml file, however it still does not seem to have the docker daemon running. Is additional configuration required?

I'm using the Gitlab Runner on Kubernetes - installed directly via the Gitlab web interface / admin.

image: docker:latest
services:
  - docker:dind
stages:
  - build
  - deploy

build-web:
  stage: build
  script:
    - docker info
  only:
    - master

deploy-web:
  stage: deploy
  script:
    - docker info
    - exit 1
  only:
    - master

Build output:

Running with gitlab-runner 12.2.0 (a987417a)
  on runner-gitlab-runner-857c466884-kzql9 BB7a6A8L
Using Kubernetes namespace: gitlab-managed-apps
Using Kubernetes executor with image docker:latest ...
Waiting for pod gitlab-managed-apps/runner-bb7a6a8l-project-1-concurrent-0prm8w to be running, status is Pending
Waiting for pod gitlab-managed-apps/runner-bb7a6a8l-project-1-concurrent-0prm8w to be running, status is Pending
Running on runner-bb7a6a8l-project-1-concurrent-0prm8w via runner-gitlab-runner-857c466884-kzql9...
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/root/cinema/.git/
Created fresh repository.
From http://mygitlab.ddns.net/root/cinema
 * [new branch]      master     -> origin/master
Checking out e138a25e as master...

Skipping Git submodules setup
$ docker info
Client:
 Debug Mode: false

Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info
ERROR: Job failed: command terminated with exit code 1

I see the following config in the gitlab runner pod:

bash-4.4$ cat .gitlab-runner/config.toml 
listen_address = "[::]:9252"
concurrent = 4
check_interval = 3
log_level = "info"

[session_server]
  session_timeout = 1800

[[runners]]
  name = "runner-gitlab-runner-857c466884-kzql9"
  request_concurrency = 1
  url = "http://mygitlab.ddns.net/"
  token = "BB7a6A8LRvZ4Y-9KsLvj"
  executor = "kubernetes"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  [runners.kubernetes]
    host = ""
    bearer_token_overwrite_allowed = false
    image = "ubuntu:16.04"
    namespace = "gitlab-managed-apps"
    namespace_overwrite_allowed = ""
    privileged = true
    service_account_overwrite_allowed = ""
    pod_annotations_overwrite_allowed = ""
    [runners.kubernetes.pod_security_context]
    [runners.kubernetes.volumes]
-- Chris Stryczynski
docker
gitlab
gitlab-ci-runner
kubernetes

1 Answer

10/14/2019

Warning: The below might not be 100% secure

Seems to be the issue mentioned here: https://gitlab.com/gitlab-org/gitlab-runner/issues/4501

A workaround is provided here: https://gitlab.com/gitlab-org/gitlab-runner/issues/4501#note_194648457

Essentially set the following:

# .gitlab-ci.yml
variables:
  DOCKER_TLS_CERTDIR: ""
-- Chris Stryczynski
Source: StackOverflow