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.
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.
There are some external tools that let you mimic this behaviour. For example, with the dockerize tool you can wrap your
CMD
orENTRYPOINT
withdockerize -wait
and that will prevent running your application until specified services are ready.If your docker-compose file used to look like this:
then you can use
dockerize
in yourv3
compose file like this: