Containers alpine1 and alpine2 are on a user-defined bridge meinebridge, alpine3 is on the default bridge, and alpine4 is on both. From alpine2, what can you reach, and what can alpine3 reach?
From alpine2: alpine1 and alpine4 by name and IP, but not alpine3 at all. alpine3 can only reach alpine4, by its default-bridge IP, not by name.
From alpine2 (on meinebridge):
| Target | By name | By IP |
|---|---|---|
alpine1 (meinebridge) |
Yes | Yes |
| alpine4 (both networks) | Yes | Yes, its meinebridge address |
alpine3 (default bridge) |
No | No |
From alpine3 (on the default bridge): alpine4 answers at its default-bridge IP, but its name does not resolve (no DNS on the default bridge). alpine1 and alpine2 cannot be reached at all.
The two lessons:
- Networks separate containers. Docker installs iptables rules that drop traffic between different bridge networks, so containers can be segmented by placing them on different networks, much like VLANs.
- User-defined networks have DNS. On them, Docker's embedded DNS resolves container names, which is what lets a web app connect to
databaseinstead of a changing IP.
A container on several networks (alpine4, added with docker network connect bridge alpine4) has one endpoint per network and can talk to both sides. It does not route between them.
* alpine4 straddles both networks; traffic between the bridges is dropped. *
Go deeper:
Docker Docs: Networking with standalone containers — the same four-container exercise in the official tutorial.
Docker Docs: Packet filtering and firewalls — the iptables rules that isolate networks from each other.