DELAPARRA
Index
Color
NL
Category: Docker

depends_on

Explained by Updated

What is depends_on?

depends_on: Declares startup order between services. With a condition it can wait until a dependency is healthy. In Docker Compose, depends_on controls the order services start in. If web depends on db, Compose starts the database container first. On its own, it only waits for the container to start, not for the service inside to be ready. A database container can be running for several seconds before it accepts connections, and your app may crash in the meantime.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about depends_on

What should you keep in mind with depends_on?

Add a health check to the database service and use condition: service_healthy. Compose then waits until the health check passes before starting the app. Even so, build your application to retry connections for a short while at start-up. In production, on Kubernetes or elsewhere, start order is not guaranteed at all, and an app that retries gracefully survives restarts of its dependencies.

What does an example of depends_on look like?

services: web: depends_on: db: condition: service_healthy

At a glance

CategoryDocker
Explained by
Updated

More Docker terms

All terms starting with D

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.