gpt4 book ai didi

docker - GitLab Ci 与 docker runner - 多阶段

转载 作者:行者123 更新时间:2023-12-04 15:52:24 24 4
gpt4 key购买 nike

我正在设置我的第一个 GitLab Ci 管道,包括 docker 来运行我的项目。我想将我的管道分成几个阶段,所以我创建了“构建”、“测试”和“清理构建”。

在这种情况下,一切正常:

stages:
- build
- test
- clean

image: docker:latest

services:
- docker:dind

before_script:
- export RELEASE=${CI_BUILD_REF_NAME}
- docker version

build:
stage: build
tags:
- sendis-dind
script:
- echo "Hallo in Build Stage"

test:
stage: test
tags:
- sendis-dind
script:
- echo "Hallo in TEST Stage"

clean-build:
stage: clean
tags:
- sendis-dind
script:
- echo "Hallo beim Clean Up"
when: always

所有 3 个阶段都成功运行

但这失败了:
stages:
- build
- test
- clean

image: docker:latest

services:
- docker:dind

before_script:
- export RELEASE=${CI_BUILD_REF_NAME}
- docker version

build:
stage: build
tags:
- sendis-dind
script:
- apk add --update py-pip
- pip install docker-compose
- docker --version
- docker-compose --version
- docker-compose -p ${RELEASE} build
- docker-compose -p ${RELEASE} up -d

test:
stage: test
tags:
- sendis-dind
script:
- docker exec ${RELEASE}_phpfpm_1 bash -c "cd /app; composer install; make runTests"

clean-build:
stage: clean
tags:
- sendis-dind
script:
- docker-compose -p ${RELEASE} down --volumes
when: always

来自第二阶段的以下消息
Running with gitlab-ci-multi-runner 9.1.1 (6104325)
on sendis-dind-runner (8b9eca1e)
Using Docker executor with image docker:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image docker:dind ID=sha256:559dd16b4e0a64d9de2447d3de234743046443f770bf5226f45f9b7f9c68887b for docker service...
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 docker:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image docker:dind ID=sha256:559dd16b4e0a64d9de2447d3de234743046443f770bf5226f45f9b7f9c68887b for docker service...
ERROR: Preparation failed: Error response from daemon: Conflict. The container name "/runner-8b9eca1e-project-140-concurrent-0-docker" is already in use by container "db166f7894856c245c6a4f5318326c5f3b6ab82d82157961d18b079444153113". 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 docker:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image docker:dind ID=sha256:559dd16b4e0a64d9de2447d3de234743046443f770bf5226f45f9b7f9c68887b for docker service...
ERROR: Preparation failed: Error response from daemon: Conflict. The container name "/runner-8b9eca1e-project-140-concurrent-0-docker" is already in use by container "db166f7894856c245c6a4f5318326c5f3b6ab82d82157961d18b079444153113". 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-8b9eca1e-project-140-concurrent-0-docker" is already in use by container "db166f7894856c245c6a4f5318326c5f3b6ab82d82157961d18b079444153113". You have to remove (or rename) that container to be able to reuse that name.

最佳答案

不同的阶段仅相互共享工件,但它们是单独的 docker 容器。这意味着如果你运行 docker-compose up -d在您的构建阶段,容器未在测试阶段运行。

仅在非常特定的用例中才需要将 dind 与 gitlab-ci 结合使用。在您的情况下,您根本不需要 dind。您可以在测试步骤中简单地使用 php-fpm 图像,因为 gitlab-ci 已经在 docker 上运行。

test:
stage: test
image: <your php-fpm image here>
script:
- cd /app
- composer install
- make runTests

关于docker - GitLab Ci 与 docker runner - 多阶段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43851720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com