How do you expose a container only to the local host, not the internet?
BeginnerScenarioNetworking and Compose
Answer
Situation read → -p 5432:5432 binds to 0.0.0.0 and Docker inserts iptables rules that bypass ufw.
What I'd do → -p 127.0.0.1:5432:5432, or do not publish at all and let other containers connect over the Docker network. For Compose: ports: ["127.0.0.1:5432:5432"].
Why → Published ports are DNAT'd in the DOCKER chain before most host firewall rules.
Interview tip → Use the DOCKER-USER chain for custom filtering.
More on Networking and Compose
Containers on the default bridge cannot resolve each other by name. Why, and what do you do?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`?IntermediateTwo Compose projects need to talk to each other.Intermediate