【问题标题】:Gitlab Runner cannot run `docker` commands in `docker` executorGitlab Runner 无法在 docker 执行器中运行 docker 命令
【发布时间】:2021-09-17 13:14:17
【问题描述】:

这让我发疯了,因为我认为我完全按照 GitLab 的文档设置 DIND using socket in GitLab Runner,因此我可以在 Gitlab CI 作业中运行 docker 命令。但它不断给出以下错误-

Running with gitlab-runner 14.0.0 (3b6f852e)
  on Gitlab-HiddenLayer-Group-Runner GosSpAyH
Preparing the "kubernetes" executor
00:00
Using Kubernetes namespace: gitlab
Using Kubernetes executor with image docker:19.03.12 ...
Using attach strategy to execute scripts...
Preparing environment
00:07
Waiting for pod gitlab/runner-gosspayh-project-27874308-concurrent-0qkp2h to be running, status is Pending
Waiting for pod gitlab/runner-gosspayh-project-27874308-concurrent-0qkp2h to be running, status is Pending
    ContainersNotReady: "containers with unready status: [build helper]"
    ContainersNotReady: "containers with unready status: [build helper]"
Running on runner-gosspayh-project-27874308-concurrent-0qkp2h via gitlab-runner-gitlab-runner-6984874897-l9z5z...
Getting source from Git repository
00:02
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/GosSpAyH/0/hiddenlayer/hl-tech-blog/.git/
Created fresh repository.
Checking out c48b6257 as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:00
$ docker info
Client:
 Debug Mode: false
Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info
Cleaning up file based variables
00:01
ERROR: Job failed: command terminated with exit code 1

这是我在 values.yaml 中的 toml 配置,用于在我的私有 Kubernetes 集群中安装 GitLab Runner。

  config: |
    [[runners]]
      url = "https://gitlab.com/"
      executor = "docker"
      privileged = true
      [runners.docker]
        tls_verify = false
        image = "docker:19.03.12"
        privileged = true
        disable_cache = false
        volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
      [runners.cache]
        Insecure = false

我的 .gitlab-ci.yml 如下 -

image: docker:19.03.12

variables:
  DOCKER_DRIVER: overlay2

before_script:
    - docker info
    - echo "$CI_REGISTRY_USER | $CI_REGISTRY_PASSWORD | $CI_REGISTRY"
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY

build:
  stage: build
  # Default branch leaves tag empty (= latest tag)
  # All other branches are tagged with the escaped branch name (commit ref slug)
  script:
    - |
      if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
        tag=""
        echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
      else
        tag=":$CI_COMMIT_REF_SLUG"
        echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
      fi
    - docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" -f deploy/Dockerfile .
    - docker push "$CI_REGISTRY_IMAGE${tag}"

注意:我有意从 .gitlab-ci.yaml 文件中保留 docker-dind 服务,因为文档说不需要它。

附加信息:

  • Kubernetes 版本:1.20
  • Gitlab 运行器版本:14.0.0

在 CI 中运行 docker 命令是一个非常常见的工作流程,我开始思考如果设置这么难,我不妨回到使用 Jenkins 的旧方法。

【问题讨论】:

  • 添加“whoami | xargs groups”作为 before_script 的第一步,以检查用户是否在 docker 组中。否则你应该添加它:“whoami | xargs sudo usermod -aG docker”
  • 我收到了 - usermod command not found。看起来执行器的图像没有安装 usermod。此外,用户是 root,所以即使我们能够运行 usermod 命令,也不确定这是否会产生任何影响。对 GitLab Runner 非常失望

标签: gitlab gitlab-ci gitlab-ci-runner


【解决方案1】:

看看升级到GitLab 14.3(2021 年 9 月)是否有帮助:

支持 Kubernetes 1.20

在 GitLab 14.3 中,我们添加了对 Kubernetes 1.20 版的支持。

GitLab 用户可以从具有许多功能的最新集群版本中受益,例如 GitLab Kubernetes AgentAuto DevOpsCluster Management Project

您可以找到supported versions and related timelines in our documentation的列表。

请参阅 DocumentationEpic

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 2020-06-28
    • 1970-01-01
    • 2019-05-05
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多