You need containers on different hosts to communicate privately.
AdvancedScenarioNetworking and Compose
Answer
Situation read → Bridge networks are host-local.
What I'd do → Docker Swarm overlay network (docker network create -d overlay --attachable --opt encrypted app), which uses VXLAN on UDP 4789 plus ports 2377/7946. Otherwise use Kubernetes CNI, or WireGuard mesh between hosts.
Why → Overlay encapsulates traffic across hosts; --opt encrypted adds IPsec at a CPU cost.
Interview tip → Open firewall ports 2377/tcp, 7946/tcp+udp, 4789/udp.
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