【问题标题】:Why local Gitlab runner isn't detecting running Docker instance?为什么本地 Gitlab runner 没有检测到正在运行的 Docker 实例?
【发布时间】:2022-01-01 21:07:42
【问题描述】:

我刚刚在我的 Ubuntu 机器上本地安装了 Gitlab-runner,因此我可以在不使用共享运行器的情况下调试我的管道。

我收到此错误输出:

$ 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

当我运行docker --version 时,我得到: Docker version 20.10.12, build e91ed57

当我运行 sudo systemctl status docker 时,我得到:

● 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

所以它已安装并运行,因此错误输出令人困惑。

这是我的管道:

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

我开始运行执行gitlab-runner exec docker --docker-privileged job

关于为什么跑步者抱怨 Docker 没有运行的任何建议?

更新:基于此线程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

错误输出:

$ 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

【问题讨论】:

    标签: docker ubuntu gitlab gitlab-ci-runner


    【解决方案1】:

    奇怪的是,对我有用的是这样确定 dind 版本:

    services:
      - docker:18.09-dind
    

    【讨论】:

    • 有意思,如果把版本改成docker:20.10-dind会怎么样?
    • 我刚刚尝试了 20.10 版本,它又给了我错误。
    【解决方案2】:

    您系统中的 docker 正在使用哪个端口?它似乎在非默认端口中运行。尝试将此添加到您的 .gitlab-ci.yaml 文件中,但更改 2375 端口。

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

    【讨论】:

    • 想法不错,但没什么区别。
    猜你喜欢
    • 2012-01-26
    • 2020-11-13
    • 2019-08-20
    • 2022-01-11
    • 2021-08-09
    • 2020-12-25
    • 2020-12-12
    • 2021-06-28
    • 1970-01-01
    相关资源
    最近更新 更多