Controlling startup order (Compose)
Controlling startup order in Compose
You can control the order of service startup with the depends_on option. Compose always starts containers in dependency order, where dependencies are determined by depends_on
, links
, volumes_from
and network_mode: "service:..."
.
However, Compose will not wait until a container is “ready” (whatever that means for your particular application) - only until it’s running. There’s a good reason for this.
The problem of waiting for a database (for example) to be ready is really just a subset of a much larger problem of distributed systems. In production, your database could become unavailable or move hosts at any time. Your application needs to be resilient to these types of failures.
To handle this, your application should attempt to re-establish a connec