Home > Enterprise >  Why local Gitlab runner isn't detecting running Docker instance?
Why local Gitlab runner isn't detecting running Docker instance?

Time:01-03

I've just installed Gitlab-runner locally on my Ubuntu machine so I can debug my pipeline without using shared runners.

I'm getting this error output:

$ docker-compose up -d --build
Couldn't connect to Docker daemon at http://docker:2375 - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
ERROR: Failed to cleanup volumes
ERROR: Job failed: exit code 1

FATAL: exit code 1

when I run docker --version I get: Docker version 20.10.12, build e91ed57

and when I run sudo systemctl status docker I get:

● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-01-01 20:26:25 GMT; 37min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 1404 (dockerd)
      Tasks: 20
     Memory: 112.0M
     CGroup: /system.slice/docker.service
             └─1404 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

so it is installed and running hence the error output is confusing.

Here's my pipeline:

image: docker:stable

services:
  - docker:dind

stages:
  - build
  - test

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .npm
    - cache/Cypress
    - node_modules

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 docker-compose
    - docker-compose up -d --build
    - docker logs testdriven_e2e:latest -f

after_script:
    - docker-compose down

I start the running executing gitlab-runner exec docker --docker-privileged job

Any suggestion as to why the runner is complaining about Docker not running ?

update: based on opinions from this thread https://gitlab.com/gitlab-org/gitlab-runner/-/issues/1986

    image: docker:stable
    
    variables:
      DOCKER_HOST: tcp://localhost:2375
      DOCKER_DRIVER: overlay2
    
    services:
      - docker:dind
    
    stages:
      - build
      - test
    
    
    cache:
      key: ${CI_COMMIT_REF_SLUG}
      paths:
        - .npm
        - cache/Cypress
        - node_modules
    
    before_script:
        - docker info
        - 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

config.toml:

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "testdriven"
  url = "https://gitlab.com/"
  token = "yU2yn4eUmFJ-xr3HzzmE"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
    insecure = false
  [runners.docker]
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    cache_dir = "cache"
    tls_verify = false
    image = "docker:stable"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    shm_size = 0

error output:

$ docker info
Client:
 Debug Mode: false

Server:
ERROR: Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?
errors pretty printing info
ERROR: Failed to cleanup volumes
ERROR: Job failed: exit code 1

FATAL: exit code 1

CodePudding user response:

Strangely, what worked for me was pinning down the dind version like this:

services:
  - docker:18.09-dind

CodePudding user response:

Which port is being used by docker in your system? It seems that it's running in a non-default port. Try adding this to your .gitlab-ci.yaml file, but change the 2375 port.

  variables:
      DOCKER_HOST: "tcp://docker:2375"
  • Related