Chapter 7: Docker Commands, Networks, Volumes and Compose
7.8 Small Compose habits
Healthcheck. depends_on with condition: service_healthy waits until Postgres accepts connections.
One project name. Compose labels resources with the folder name by default. Stay in one folder so down cleans the right stack.
Layout. Keep the Compose file next to the Dockerfile so build: . is obvious: Dockerfile, .dockerignore, .env.example, gitignored .env, compose.yaml, and the app file.
Rebuild. docker compose up -d --build after a Dockerfile edit.
Restart on a lab VM.
services:
api:
restart: unless-stopped
Useful after a reboot. It is not Kubernetes. That comes later.
Override. compose.override.yaml can hold a laptop-only bind mount. Do not commit an absolute path that works on only one laptop.
Check the merge. docker compose config prints the merged YAML. Fix indentation before you start the stack.
Do not scale the database service in this lab. A stateless API can be scaled later. Published ports and one database need care you do not need tonight.
Revision card
Interview card