dockerdocker-compose

What is the alternative to condition form of depends_on in docker-compose Version 3?


docker-compose 2.1 offers the nice feature to specify a condition with depends_on. The current docker-compose documentation states:

Version 3 no longer supports the condition form of depends_on.

Unfortunately the documentation does not explain, why the condition form was removed and is lacking any specific recommondation on how to implement that behaviour using V3 upwards.


Solution

  • Update Nov 2024:

    The current Docker Compose v2 supports "depends_on". However, it is only used to specify the order of startup and shutdown of services, and only when starting/shutting down all dependent services together (docker compose up/down). It will not automatically restart or shutdown dependent services if only one is killed. That's a more complex topic.

    The docker compose versioning is a mess. What used to be version 3 was replaced by "v2" starting in June 2021.

    --- old answer (pre v2) ----

    There's been a move away from specifying container dependencies in compose. They're only valid at startup time and don't work when dependent containers are restarted at run time. Instead, each container should include mechanism to retry to reconnect to dependent services when the connection is dropped. Many libraries to connect to databases or REST API services have configurable built-in retries. I'd look into that. It is needed for production code anyway.