Reputation: 380
im setting up my first GitLab Ci Pipeline including docker to run my project. I wanted to divide my pipeline into several stages so i created "build", "test", and "clean-build".
In this scenario everything works fine:
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
All 3 stages are run successfully
but this fails:
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
with the following message from second stage
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.
Upvotes: 6
Views: 2656
Reputation: 1051
Different stages only share artifacts with each other, but they're separate docker containers. That means that if you run docker-compose up -d
in your build stage, the containers are not running in the test stage.
Combining dind with gitlab-ci is only necessary in very specific use-cases. In your case, you don't need dind at all. You can simply use the php-fpm image in your test step, since gitlab-ci is already running on docker.
test:
stage: test
image: <your php-fpm image here>
script:
- cd /app
- composer install
- make runTests
Upvotes: 1