Docker · Containers in practice

How does traffic flow between containers and the outside world?

HardnetworkingnatdnsUpdated Oct 2026
Quiz this track

Short answer

Containers get an IP on a bridge network, and published ports are forwarded through host NAT rules. Embedded DNS resolves service names, while overlay networks carry traffic across hosts.

On a bridge network, each container gets a veth pair connected to a Linux bridge and an address in the bridge subnet. Outbound traffic is masqueraded to the host IP. Inbound traffic reaches a container only through a published port, which installs DNAT rules.

sh
docker network inspect app-net
docker exec api-1 ip addr
docker exec api-1 cat /etc/resolv.conf
docker run --rm --network container:api-1 nicolaka/netshoot dig db
The embedded DNS server is usually 127.0.0.11, and service names resolve through it.

Modes and their trade-offs

  • bridge: isolated subnet with NAT, the common default
  • host: no network namespace, so the container shares host ports and interfaces
  • overlay: VXLAN encapsulation across hosts, with extra MTU and latency overhead
  • macvlan: a routable MAC and IP on the physical network, bypassing NAT
  • none: no connectivity, useful for isolated processing

Overlay networks add encapsulation, so the underlay MTU must be large enough or large packets fragment or stall. This shows up as TLS handshakes or large uploads hanging while small requests work.

Container IPs are not stable across restarts. Always address services by name or a service discovery mechanism, never by a cached container IP.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What is the role of 127.0.0.11 inside a container?
  2. 2Why can overlay networking cause MTU-related hangs?
  3. 3When would you choose macvlan?
  4. 4Why should you not hardcode a container IP?

Say it in the interview

On a bridge network a container gets a veth pair and a private IP, outbound traffic is NATed, and inbound traffic requires a published port. Docker's embedded DNS resolves service names, which is why I never hardcode container IPs. For multi-host traffic I use an overlay, but I watch MTU because encapsulation can cause large packets to stall.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Docker mock interview and get scored feedback on depth, clarity and confidence.