Chapter 7: Docker Volumes, Networks and Compose
7.7 Small Compose habits that save hours
Healthchecks. depends_on with condition: service_healthy waits until Postgres accepts connections — fewer "connection refused on first boot" flakes.
One project name. Compose labels resources with a project name (folder name by default). Stay inside one folder so down cleans the right stack.
Rebuild when Dockerfile changes. up --build or docker compose build api after Dockerfile edits.
Exec into a service.
docker compose exec api sh
docker compose exec db psql -U postgres
Scaling (awareness only). docker compose up -d --scale api=2 is possible for stateless APIs — but published ports and sticky DB sessions need care. Do not force-scale the database service in this beginner lab.