Make a database reachable only by the app, and the app only through a reverse proxy, on a single host.
IntermediateScenarioNetworking and Compose
Answer
Situation read → Minimise published ports.
What I'd do → Publish only the proxy (80/443). DB and app have no ports: entries and sit on private networks. Verify:
docker compose ps --format '{{.Name}} {{.Ports}}'
ss -tlnp | grep docker-proxy
Why → Unpublished services are unreachable from outside the Docker networks.
Interview tip → Scan the host with nmap to confirm.
More on Networking and Compose
Containers on the default bridge cannot resolve each other by name. Why, and what do you do?BeginnerHow do you expose a container only to the local host, not the internet?BeginnerDesign a Compose file for web + api + postgres + redis with correct startup ordering.IntermediateFrontend must reach the API but not the database. Segment the network.IntermediateA container needs to call a service running on the Docker host.BeginnerWhen would you use `--network host`?Intermediate