Why Gitlab runner throws "Is the docker daemon running?"
Asked Answered
A

3

5

I was hoping to get some assistance with Gitlab runner instance which throws "Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?"

my gitlab-ci.yml:

image: docker:18.09-dind

variables:
  DOCKER_HOST: tcp://localhost:2375
  DOCKER_DRIVER: overlay2


stages:
  - build
  - test

before_script:
    - export REACT_APP_USERS_SERVICE_URL=http://127.0.0.1

job:
  stage: build
  script:
    - apk add --update --no-cache gcc g++ make python2 python2-dev py-pip python3-dev curl
    - curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    - chmod +x /usr/local/bin/docker-compose
    - docker-compose up -d --build
    - docker logs testdriven_e2e:latest -f

after_script:
    - docker-compose down

error output:

(32/34) Installing pkgconf (1.6.1-r1)
(33/34) Installing python2-dev (2.7.18-r0)
(34/34) Installing python3-dev (3.7.10-r0)
Executing busybox-1.30.1-r2.trigger
OK: 339 MiB in 73 packages
$ curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   664  100   664    0     0   2699      0 --:--:-- --:--:-- --:--:--  2688
100 23.5M  100 23.5M    0     0  3546k      0  0:00:06  0:00:06 --:--:-- 4406k
$ chmod +x /usr/local/bin/docker-compose
$ docker-compose up -d --build
Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?
ERROR: Job failed: exit code 1

FATAL: exit code 1  

Thank you in advance for any suggestions.

Anatomical answered 21/1, 2022 at 19:41 Comment(0)
B
11

You must add the docker-in-docker service, then set the daemon host to the hostname docker (which is the hostname of the dind service)

image: docker

services:
  - docker:dind

variables:
  DOCKER_HOST: tcp://docker:2375
  DOCKER_TLS_CERTDIR: ""
  DOCKER_DRIVER: overlay2
Bryozoan answered 22/1, 2022 at 14:45 Comment(1)
as i understand, this disables tls, but yeah, it works for me, thxOgata
C
2

Summarized

@sytech ans helped me. But if you still have no issue please check below things

  1. When you register your gitlab runner make sure you have --docker-privileged

Example:

sudo gitlab-runner register -n --url https://your_gitlab.com --registration-token project_token --executor docker --description "Deployment Runner" --docker-image "docker:stable" --tag-list deployment --docker-privileged
  1. Give permission to Gitlab-runner to run docker commands
sudo usermod -aG docker gitlab-runner
  1. As @sytech mentioned also add the below code in your yml file
variables:
  DOCKER_HOST: tcp://docker:2375
  DOCKER_TLS_CERTDIR: ""
  DOCKER_DRIVER: overlay2

Let me know if you still have an issue

Comines answered 12/1, 2023 at 9:51 Comment(0)
A
0
"According to the provided configuration, it still throws an error."
Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?
config.toml  config 

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    type = "s3"
    Shared = true
  [runners.cache.s3]
    ServerAddress = "192.168.10.190:30070"
    AccessKey = "minio"
    SecretKey = "minio123456"
    BucketName = "gitlab-cache"
    Insecure = true
  [runners.docker]
    tls_verify = false
    image = "docker:20.10.20"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    allowed_pull_policies = ["if-not-present"]
    pull_policy = ["if-not-present"]
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    shm_size = 0
Afterpiece answered 9/4 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.