Docker Compose Files and YAML Patterns/Simple service dependency

Starts `db` before `web` in dependency order.

Section: Dependencies and Healthchecks

Simple service dependency

yaml
yaml
services:
  web:
    image: myapp:latest
    depends_on:
      - db
  db:
    image: postgres:16
Explanation

Order alone does not guarantee the dependency is ready for traffic.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Dependencies and Healthchecks
Wait for healthy dependency
Uses health state as the dependency condition for startup ordering.
OpenIn sheetyamlsame section
Healthcheck on a service
Defines a readiness-style health check for the service.
OpenIn sheetyamlsame section
Minimal web + db stack
Simple two-service stack with port publishing and environment variables.
OpenIn sheetyaml2 tag match
Environment as key/value map
Provide container environment values inline in YAML.
OpenIn sheetyaml2 tag match
Define optional profiles
Marks a service as optional unless its profile is enabled.
OpenIn sheetyaml2 tag match
Service built from Dockerfile
Build a service image from local source while also tagging it.
OpenIn sheetyaml2 tag match