Ravindra BagaleCourses & study guides

Chapter 7: Docker Volumes, Networks and Compose

7.1 Why volumes and networks — two services, one private network

One container is enough for a hello API. Real apps need a database (or Redis cache) beside the API. Those two processes must talk on a private path, and the database files must survive container restarts.

Why it matters for an Instagram-style badge API : the badge API stores profile badge rows in Postgres. If you recreate the DB container and lose the volume, data vanishes — users see empty results.

Need Docker idea
Keep DB files after docker rm Volume (or careful bind mount)
API reaches DB by name, not public IP User-defined network
Start API + DB with one command Compose

Ports stay logical published ports: the API might publish host 8080 → container 8080 for your browser. The DB counter (5432) should usually stay inside the private lane — not published to the world on a public VM.

Ravindra Bagale's Tip

Khup students DB -p 5432:5432 public cloud VM var sodtat "for convenience". Lab asel tari Security Group tight theva (AWS course madhe SG shikle aahet). Prod madhe DB private network. Dhyan rakho!