Gitlab准备失败:来自守护程序的错误响应:冲突。容器名称已被容器使用

时间:2019-09-17 14:49:21

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

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

我有一个应用程序,我在其中使用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.

我尝试禁用辅助缓存,但对我而言无效。

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

任何帮助,将不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:1)

这是一个已知问题,请参见https://gitlab.com/gitlab-org/gitlab-runner/issues/4327。 GitLab正在重新使用相同的服务容器名称。如果未及时删除先前的容器,则此方法将失败。

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

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

由于我们面临与Docker执行器相同的问题,我们目前通过使用Docker + Machine执行器来解决该问题。尽管您不能完全确定避免该错误,但是从我的经验来看,此后作业运行更加可靠。但是,要权衡的是,对于每个作业,都要配置要支付的VM。