簡體   English   中英

為什么本地 Gitlab 運行器未檢測到正在運行的 Docker 實例?

[英]Why local Gitlab runner isn't detecting running Docker instance?

我剛剛在我的 Ubuntu 機器上本地安裝了 Gitlab-runner,因此我可以在不使用共享運行器的情況下調試我的管道。

我收到此錯誤 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

當我運行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

因此它已安裝並運行,因此錯誤 output 令人困惑。

這是我的管道:

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

錯誤 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

奇怪的是,對我有用的是這樣確定 dind 版本:

services:
  - docker:18.09-dind

docker 在您的系統中使用哪個端口? 它似乎在非默認端口中運行。 嘗試將此添加到您的.gitlab-ci.yaml文件中,但更改 2375 端口。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM