Recommended Docker Compose service field-order

Recommended sequence (most common in official Compose examples and production teams):

  1. image / build → What the service is
  2. command → How it runs (if overridden)
  3. ports → External access (if any)
  4. volumes → Data persistence
  5. environment → Configuration
  6. depends_on / links / networks → Dependencies and networking
  7. healthcheck → Readiness/liveness probes
  8. restart → Restart policy (if used)