Chapter 7: Docker Volumes, Networks and Compose
7.10 Lab — Compose stack with persistent data
Lab
Bring up badge API API + Postgres with Compose and prove data survives restart.
- In your app repo, add
compose.yamlwithapi(build) +db(postgres image), shared network, named volume. - Add
.env(gitignored) and.env.example(committed placeholders). - Ensure
.gitignorelists.env. docker compose up -d --build- Hit API health on the published host counter (for example
8080). - Write one piece of data (SQL insert or API POST — your choice).
docker compose downthenup -d— confirm data still there.docker compose logs api— save two interesting lines in your notes.- When finished for the day:
docker compose down(keep volume) ordown -vonly if you want a clean wipe.
Practice task
Draw (or list) street door vs private corridor for your stack: which service publishes a host port, which does not, and why.
Thodkyaat sangaycha tar
- Volumes keep DB files across container recreate; prefer named volumes for lab data.
- User-defined networks give service-name DNS on a private lane; do not publish DB counters publicly without need.
- Compose describes multi-service stacks in YAML —
up/down/logs/ps. .envfor local secrets; never commit real passwords; use.env.examplefor teammates.downkeeps volumes;down -vdeletes them — use deliberately.
Samajla ka? Nasel tar lab (7.10) sodun volume survive prove kara – `down` nantar data tikun asava. Aata pudhe jaauya CI/CD concepts kade.