为什么本地 Gitlab 运行器没有检测到正在运行的 Docker 实例?



我刚刚在Ubuntu机器上本地安装了Gitlab runner,这样我就可以在不使用共享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

奇怪的是,对我有效的是固定这样的dind版本:

services:
  - docker:18.09-dind

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

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

相关内容

  • 没有找到相关文章

最新更新