Interview Prep/Docker/Networking and Compose

Frontend must reach the API but not the database. Segment the network.

IntermediateScenarioNetworking and Compose
Answer

Situation read → Least-privilege networking.

What I'd do →

services:
  web: { networks: [front] }
  api: { networks: [front, back] }
  db:  { networks: [back] }
networks:
  front: {}
  back: { internal: true }

Why → db shares no network with web; internal: true also blocks outbound internet for the back tier.

Interview tip → Network aliases give stable names per network.

All Docker questions Roadmap: Docker & containers

More on Networking and Compose