I am setting up a test infrastructure using docker-compose. I want to use the docker-compose option --exit-code-from
to return the exit code from the container that is running tests. However, I also have a container that runs migrations on my database container using the sequelize cli. This migrations container exits with code 0 when migrations are complete and then my tests run. This causes an issue with both the --exit-code-from
and --abort-on-container-exit
options. Is there a way to ignore when the migration container exits?
--exit-code-from
implies --abort-on-container-exit
, which according to documentation
--abort-on-container-exit Stops all containers if any container was stopped.
But you could try:
docker inspect <container ID> --format='{{.State.ExitCode}}'
You can get a list of all (including stopped) containers with
docker container ls -a
Here's a nice example: Checking the Exit Code of Stopped Containers
sleep 300
at the end of your migration or ephemeral container, this "guarantees" that the test fails after 5 minutes since it would exit and be caught by --abort-on-container-exit
. –
Liddie Don't use docker-compose up
for running one-off tasks. Use docker-compose run
instead, as the documentation suggests:
The docker-compose run command is for running “one-off” or “adhoc” tasks. It requires the service name you want to run and only starts containers for services that the running service depends on. Use run to run tests or perform an administrative task such as removing or adding data to a data volume container. The run command acts like docker run -ti in that it opens an interactive terminal to the container and returns an exit status matching the exit status of the process in the container.
Source: https://docs.docker.com/compose/faq/
For example:
docker-compose build my_app
docker-compose run db_migrations # this starts the services it depends on, such as the db
docker-compose run my_app_tests
--exit-code-from
implies --abort-on-container-exit
, which according to documentation
--abort-on-container-exit Stops all containers if any container was stopped.
But you could try:
docker inspect <container ID> --format='{{.State.ExitCode}}'
You can get a list of all (including stopped) containers with
docker container ls -a
Here's a nice example: Checking the Exit Code of Stopped Containers
sleep 300
at the end of your migration or ephemeral container, this "guarantees" that the test fails after 5 minutes since it would exit and be caught by --abort-on-container-exit
. –
Liddie © 2022 - 2024 — McMap. All rights reserved.