I am trying to understand the relationship between:
eth0
on the host machine; anddocker0
bridge; andeth0
interface on each container
It is my understanding that Docker:
- Creates a
docker0
bridge and then assigns it an available subnet that is not in conflict with anything running on the host; then - Docker binds
docker0
toeth0
running on the host; then - Docker binds each new container it spins up to
docker0
, such that the container'seth0
interface connects todocker0
on the host, which in turn is connected toeth0
on the host
This way, when something external to the host tries to communicate with a container, it must send the message to a port on the host's IP, which then gets forwarded to the docker0
bridge, which then gets broadcasted to all the containers running on the host, yes?
Also, this way, when a container needs to communicate to something outside the host, it has its own IP (leased from the docker0
subnet) and so the remote caller will see the message as having came from the container's IP.
So if anything I have stated above is incorrect, please begin by clarifying for me!
Assuming I'm more or less correct, my main concerns are:
- When remote services "call in" to the container, all containers get broadcasted the same message, which creates a lot of traffic/noise, but could also be a security risk (where only container 1 should be the recipient of some message, but all the other containers running on it get the message as well); and
- What happens when Docker chooses identical subnets on different hosts? In this case, container 1 living on host 1 might have the same IP address as container 2 living on host 2. If container 1 needs to "call out" to some external/remote system (not living on the host), then how does that remote system differentiate between container 1 vs container 2 (both will show the same egress IP)?