Ravindra BagaleCourses & study guides

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.

  1. In your app repo, add compose.yaml with api (build) + db (postgres image), shared network, named volume.
  2. Add .env (gitignored) and .env.example (committed placeholders).
  3. Ensure .gitignore lists .env.
  4. docker compose up -d --build
  5. Hit API health on the published host counter (for example 8080).
  6. Write one piece of data (SQL insert or API POST — your choice).
  7. docker compose down then up -d — confirm data still there.
  8. docker compose logs api — save two interesting lines in your notes.
  9. When finished for the day: docker compose down (keep volume) or down -v only 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.
  • .env for local secrets; never commit real passwords; use .env.example for teammates.
  • down keeps volumes; down -v deletes 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.