In Docker compose, is it possible for a container A to wait for a container B to finish (aka, stop running) before starting?
I have 3 containers in my docker compose:
- Container A is a MySQL database
- Container B is a Flyway container that has some SQL migrations on a certain schema1. After running the migrations, it stops.
- Container C is a Flyway container that has some SQL migrations on a certain schema2 and adds some data to both schema1 and schema2. It does also stop after running the migrations.
I need container C to wait for B to finish otherwise the migrations are going to fail.
CodePudding user response:
Since this was urgent, I ended up ditching the whole idea of knowing if a certain container had successfully ended, and I just added a restart
policy that triggers on-failure
so this way if a migration fails it can retry.
Also, since ContainerC's migrations were just repeatable data migrations I added -baselineOnMigrate="false"
to the Flyway command that was being executed there, so that way, if the migrations that ContainerB had to do were not finished yet, C's migrations would fail without polluting flyway's history therefore they could retry without issues.
CodePudding user response:
You can configure health checks in Docker-compose .