Containers on the default bridge cannot resolve each other by name. Why, and what do you do?
BeginnerScenarioNetworking and Compose
Answer
Situation read → The default bridge network has no embedded DNS for container names.
What I'd do →
docker network create appnet
docker run -d --network appnet --name db postgres:17
docker run -d --network appnet --name api myapi # reach db at db:5432
Compose does this automatically with a per-project network.
Why → User-defined bridges provide automatic service discovery and better isolation.
Interview tip → --link is legacy; do not use it.
More on Networking and Compose
How 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`?IntermediateTwo Compose projects need to talk to each other.Intermediate