You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker Compose部署多GitLab Runner遇Git错误的解决方法

问题

通过Docker Compose在单台服务器部署了10个GitLab Runner,仅某一个项目的流水线运行时频繁出现两类错误:

错误类型1

fatal: Unable to create '/builds/xxx.de/xxx.de/.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

错误类型2

Reinitialized existing Git repository in /builds/xxx.de/xxx.de/.git/
fatal: shallow file has changed since we read it

Runner配置(仅名称、ID、令牌不同)

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "runner-1-farm-1"
  url = "https://git.xyz.com/"
  id = 12
  token = "-94xSx9-blablabla"
  token_obtained_at = 2022-09-16T07:52:10Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    host = "tcp://dind:2375"
    tls_verify = false
    image = "registry.xyz.com/docker/docker:latest"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]
    shm_size = 0

Docker Compose配置

version: "3.9"

services:
  dind:
    image: docker:20-dind
    restart: always
    privileged: true
    environment:
      DOCKER_TLS_CERTDIR: ""
    command:
      - --storage-driver=overlay2

  runner_1:
    restart: always
    image: registry.gitlab.com/gitlab-org/gitlab-runner:alpine
    depends_on:
      - dind
    environment:
      - DOCKER_HOST=tcp://dind:2375
      - REGISTRATION_TOKEN=${REGISTRATION_TOKEN}
    volumes:
      - ./config:/etc/gitlab-runner:rw
解决方案

针对该项目的流水线问题,可按以下步骤排查修复:

  • 关闭浅克隆配置:若项目启用了浅克隆,直接在项目CI/CD设置的General pipelines中取消勾选Git shallow clone,或在.gitlab-ci.yml里显式添加GIT_DEPTH: 0,避免因浅克隆文件冲突触发报错。
  • 清理Git锁定文件:在流水线的before_script中添加前置清理逻辑,消除残留的锁定文件影响:
    before_script:
      - [ -f .git/index.lock ] && rm -f .git/index.lock
      - git reset --hard
    
  • 隔离Runner缓存目录:为该项目分配专属Runner,修改其配置:移除共享的/cache卷,改为项目专属缓存目录(如/cache/project-xxx:/cache),或直接设置disable_cache = true禁用缓存,避免多Runner共享缓存导致的仓库状态冲突。
  • 限制项目流水线并发:在项目CI/CD设置中,将Pipeline concurrency设为1,避免同一项目的多个流水线任务同时在Dind服务中竞争资源。
  • 升级Git版本:检查构建镜像中的Git版本,若版本较低(低于2.30),更换为包含新版Git的构建镜像,修复浅克隆相关的兼容问题。

内容的提问来源于stack exchange,提问作者Anton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 14:05:22