skip to Main Content

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.

2

Answers


  1. 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
    
    Login or Signup to reply.
  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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search