首页 > 解决方案 > Gitlab 准备失败:来自守护进程的错误响应:冲突。容器名称已被容器使用

问题描述

我在开发中使用 Gitlab CI 进行持续集成。我的 gitlab-runner 在 ubuntu 实例上运行。

我有一个应用程序,我在其中使用 MongoDB v3.6。我必须在 CI/CD 的测试阶段进行数据库集成测试。

prepare:
    image: node:11.10.1-alpine
    stage: setup
    script:
    - npm install --quiet node-gyp
    - npm install --quiet
    - npm install -g yarn
    - chmod a+rwx  /usr/local/lib/node_modules/yarn/bin/yarn*
    - chmod a+rwx  /usr/local/bin/yarn*
    - yarn install
    - cd client
    - yarn install
    - cd ../
    - cd admin
    - yarn install
    cache:
        key: "$CI_COMMIT_REF_SLUG"
        paths:
        - node_modules/
        - client/node_modules/
        - admin/node_modules/
        policy: push

app_testing:
    image: node:11.10.1-alpine
    services:
    - name: mongo:3.6
    stage: test
    cache:
        key: "$CI_COMMIT_REF_SLUG"
        paths:
        - node_modules/
        - client/node_modules/
        - admin/node_modules/
    script:
    - yarn run test
    - cd client
    - yarn run test
    - cd ../
    - cd admin
    - yarn run test

对于每个备用管道,我在 app_testing(test) 阶段收到以下错误

ERROR: Job failed (system failure): Error response from daemon: Conflict. The container name "/runner-e7ce6426-project-11081252-concurrent-0-mongo-0" is already in use by container "0964b061b56d8995966f577e7354852130915228bac1a7513a773bbb82aeefaf". You have to remove (or rename) that container to be able to reuse that name.

以下是失败的特定作业的完整日志

Running with gitlab-runner 10.8.0 (079aad9e)
  on SharedRunner-XYZGroup e7ce6426
Using Docker executor with image node:11.10.1-alpine ...
Starting service mongo:3.6 ...
Pulling docker image mongo:3.6 ...
Using docker image sha256:57c2f7e051086c7618c26a2998afb689214b4213edd578f82fe4b2b1d19ee7c0 for mongo:3.6 ...
ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Will be retried in 3s ...
Using Docker executor with image node:11.10.1-alpine ...
Starting service mongo:3.6 ...
Pulling docker image mongo:3.6 ...
Using docker image sha256:57c2f7e051086c7618c26a2998afb689214b4213edd578f82fe4b2b1d19ee7c0 for mongo:3.6 ...
ERROR: Preparation failed: Error response from daemon: Conflict. The container name "/runner-e7ce6426-project-11081252-concurrent-0-mongo-0" is already in use by container "0964b061b56d8995966f577e7354852130915228bac1a7513a773bbb82aeefaf". You have to remove (or rename) that container to be able to reuse that name.
Will be retried in 3s ...
Using Docker executor with image node:11.10.1-alpine ...
Starting service mongo:3.6 ...
Pulling docker image mongo:3.6 ...
Using docker image sha256:57c2f7e051086c7618c26a2998afb689214b4213edd578f82fe4b2b1d19ee7c0 for mongo:3.6 ...
ERROR: Preparation failed: Error response from daemon: Conflict. The container name "/runner-e7ce6426-project-11081252-concurrent-0-mongo-0" is already in use by container "0964b061b56d8995966f577e7354852130915228bac1a7513a773bbb82aeefaf". You have to remove (or rename) that container to be able to reuse that name.
Will be retried in 3s ...
ERROR: Job failed (system failure): Error response from daemon: Conflict. The container name "/runner-e7ce6426-project-11081252-concurrent-0-mongo-0" is already in use by container "0964b061b56d8995966f577e7354852130915228bac1a7513a773bbb82aeefaf". You have to remove (or rename) that container to be able to reuse that name.

我尝试禁用二级缓存,它对我不起作用。

现在我不知道如何解决这个问题。作为一种解决方法,我必须在每次失败时触发一个新的管道,这当然没有人喜欢,因为任何人自动化事情的最终目标是专注于最重要的事情。

对此的任何帮助将不胜感激。

提前致谢。

标签: gitlabgitlab-cigitlab-ci-runner

解决方案


这是一个已知问题,请参阅https://gitlab.com/gitlab-org/gitlab-runner/issues/4327。GitLab 正在重用相同的服务容器名称。如果没有及时删除之前的容器,这种方法就会失败。

如果您阅读(一长串)评论,您可能会发现一些解决方法,其中包括:

  • 将并发限制为 1
  • 增加 Runner 机器的 IOPS(例如从 HDD 切换到 SSD)

由于我们在使用 Docker 执行器时遇到了同样的问题,我们目前通过使用 Docker+Machine 执行器来解决这个问题。尽管您不能真正确保避免该错误,但我的经验是,从那时起作业运行得更加可靠。然而,折衷方案是为每个工作提供一个希望获得报酬的虚拟机。


推荐阅读