depends_on orders a project: up starts dependencies first, down stops in reverse, and docker compose up api starts what api depends on too (--no-deps skips them). The short form, a list of names, waits only until the dependency's container has started, and a started PostgreSQL 1,289 container is not yet a database that accepts connections: the race of Up, Down, Rebuild.
The long form gives each dependency a condition: service_started (the short form's behavior), service_healthy (its healthcheck reports healthy) or service_completed_successfully (a one-shot job such as a migration exited with 0). restart: true (Compose 2.17 514 ) restarts the dependent service whenever a Compose command restarts or recreates the dependency, but not when the daemon revives a crashed one, and required: false (Compose 2.20) turns a missing dependency into a warning. BookNest's API gets service_healthy and restart: true, because a restarted database drops every pooled connection.