Control startup and shutdown order in Compose
From the end of June 2023 Compose V1 won’t be supported anymore and will be removed from all Docker Desktop versions.
You can control the order of service startup and shutdown with the
depends_on option. Compose always starts and stops
containers in dependency order, where dependencies are determined by
A good example of when you might use this is an application which needs to access a database. If both services are started with
docker compose up, there is a chance this will fail since the application service might start before the database service and won’t find a database able to handle its SQL statements.
On startup, Compose does not wait until a container is “ready”, only until it’s running. This can cause issues if, for example you have a relational database system that needs to start its own services before being able to handle incoming connections.
The solution for detecting the ready state of a service is to use the
condition attribute with one of the following options:
service_healthy. This specifies that a dependency is expected to be “healthy”, which is defined with
healthcheck, before starting a dependent service.
service_completed_successfully. This specifies that a dependency is expected to run to successful completion before starting a dependent service.