I’m having some trouble with the docker container deployment in the GitLab CI pipeline. Please see my docker-compose.yml:
version: '3.9'
services:
MY_DOCKER_SERVICE_NAME:
build: .
ports:
- '${WEB_SERVER_PORT}:${WEB_SERVER_PORT}'
environment:
- PORT=${WEB_SERVER_PORT}
- MONGODB_URL=${MONGODB_URL}
volumes:
mongo-data:
and my summarised .gitlab-ci.yml:
image: node:18-alpine
stages:
- prepare
- lint
- build
- deploy
// Removed unrelavent parts
build_app:
stage: build
script:
- docker compose build --no-cache
deploy_app:
stage: deploy
script:
- docker compose up
I’ve tried to use varying docker compose commands like below in the deploy stage:
- Using
docker compose up
, causes the pipeline stuck in the running state after even a successful deployment - Using
docker compose up -d
causes the pipeline to finish without waiting for the container, leading to even failed deployments being marked as successful. - Using
docker compose --exit-code-from=MY_DOCKER_SERVICE_NAME
works great in the failure scenarios but it also stuck in the running state after successful deployments - And it’s not possible to use
-d
flag with the--exit-code-from
flag
but they’re all not working as expected. Is there any way to detect the correct container status and behave as expected in the GitLab CI?
P.S. Used process.exit(1)
to simulate failure application scenarios