Docker Networking: bridge, host, none, overlay, macvlan; Port Publishing, Embedded DNS, Compose Networks, the iptables Rules Docker Writes, MTU
"Publishing container ports is insecure by default. Meaning, when you publish a container's ports it becomes available not only to the Docker host, but to the outside world as well." — Docker documentation, Port publishing and mapping (Docker Engine networking)
Summary: A Docker container is a process in its own network namespace, wired to the host by a veth pair and a Linux bridge; Docker then writes NAT and filter rules so that containers can reach out, published ports can reach in, and different networks stay apart, and it runs a small DNS server at 127.0.0.11 so containers find each other by name.
Focus: Namespaces, veth and bridges; default vs user-defined bridges; MASQUERADE out and DNAT in; embedded DNS; host, none, container, overlay, macvlan and ipvlan; Docker Desktop's VM; Compose networks (internal, external, aliases, network_mode); the iptables/nftables chains Docker creates and why ufw does not see them; IPv6; MTU; address pools; observability and the failures you will actually meet.
Learning goal: Draw the packet path for any container conversation, predict whether a name resolves and a port is reachable, publish only what you mean to publish, design Compose networks for a Laravel or Go stack, and debug a failing connection from inside the container's own namespace.
This chapter is the complete reference for container networking on one Docker host and across hosts. It builds on IP addressing and CIDR (the subnets Docker hands out), NAT and port forwarding (MASQUERADE, DNAT and conntrack in general), DNS resolution for developers (resolv.conf, ndots, search domains), ports, sockets and connections (listen addresses, ss, tcpdump) and firewalls (netfilter chains, nftables). The pod model, CNI and Services are in Kubernetes networking; tunnels in VPNs and tunnels; a symptom-first view in the network troubleshooting playbook. The design-level topics stay in system design: containers and Kubernetes, service mesh and sidecars, load balancing, forward vs reverse proxies; the Go build and image side is in project layout, linting and Docker builds.
Everything marked "lab" below was run on Docker Desktop (engine 29.8.1, kernel 7.0.14-linuxkit, arm64). Commands that inspect the host side were run inside the Docker Desktop VM with docker run --rm -it --privileged --pid=host alpine:3 nsenter -t 1 -m -u -n -i sh; on a Linux host you run them directly with sudo.
Page map
| If you are looking for | Go to |
|---|---|
| The tables to memorise | Everything in one minute |
| Why containers need their own network at all | Why it exists |
| Versions and history of the networking stack | Where it comes from |
Namespaces, veth pairs, ip netns, nsenter | Namespaces and veth |
docker0, br-xxxxxxxxxxxx, a bridge as a switch | The bridge |
"Name does not resolve on the default bridge", --link | Default vs user-defined bridge |
| Containers reaching the internet, MASQUERADE | Egress |
-p, 127.0.0.1: binds, UDP, -P, EXPOSE | Publishing ports |
| Same network, several networks, aliases | Container to container |
127.0.0.11, --dns, search domains, ndots | Embedded DNS |
--network host, none, container: | Host mode, None and container modes |
| Swarm, VXLAN, encrypted overlay | Overlay |
| A LAN IP per container | macvlan and ipvlan |
macOS/Windows, host.docker.internal | Docker Desktop |
Compose: project network, internal, external, network_mode | Compose networks |
DOCKER-USER, DOCKER-FORWARD, ufw bypass, iptables: false | The rules Docker writes |
| IPv6, ip6tables, ULA | IPv6 |
Large responses hang, --mtu | MTU |
Subnet clashes with VPN, default-address-pools, fixed IPs | IPAM |
| NAT cost, userland proxy | Performance |
--icc, DB ports on the internet | Security |
docker network inspect, nsenter, tcpdump, netshoot | Seeing it |
| Go and Laravel code | Solving the classic problems |
| "It does not connect" table | Troubleshooting |
| Which driver for which job | Choosing |
| Monolith to distributed | In architecture |
| Reproduce everything | Lab |
| Misconceptions, cheat sheet, self-check, glossary | Misconceptions, Cheat sheet, Self-check, Glossary |
Everything in one minute
The drivers.
| Driver | In plain words | Container gets | Reachable by name | Typical use |
|---|---|---|---|---|
bridge (default bridge network) | A virtual switch on the host; legacy defaults | Own netns, IP in 172.17.0.0/16, NAT out | No (IP only, or legacy --link) | Nothing new; it exists for compatibility |
bridge (user-defined) | Same switch, one per network, with DNS and isolation | Own netns, IP from a pool, NAT out | Yes, container name, service name, aliases | Every single-host stack, every Compose project |
host | No network isolation: the host's own stack | The host's interfaces and ports | n/a | Packet tools, very many ports, lowest overhead |
none | Only loopback | lo | n/a | Batch jobs that must not talk, sandboxing |
overlay | One network across many Docker hosts, VXLAN tunnels | IP in a cluster-wide subnet | Yes | Swarm services, multi-host standalone containers |
macvlan | Each container is a separate device with its own MAC on the LAN | A LAN IP | Via LAN DNS | Legacy apps, appliances that must sit on the LAN |
ipvlan | Like macvlan but shares the parent's MAC (L2) or routes (L3) | A LAN or routed IP | Via LAN DNS | Where switches limit MACs, cloud-ish L3 setups |
container:NAME | Join another container's namespace | Exactly its interfaces | Same as that container | Debug sidecars, tcpdump, Compose service: |
Who can reach whom (user-defined bridge, default settings).
| From | To | Works? | Mechanism |
|---|---|---|---|
| Container | Container on the same network | Yes, every port, by name | L2 through the bridge, embedded DNS |
| Container | Container on another network | No (unless one joins both networks, or via a published port on a host address) | DOCKER chain DROP |
| Container | Internet | Yes | Default route to the bridge, MASQUERADE |
Container on internal: true | Internet | No route, no NAT | No default gateway |
| Host or LAN | Container port, not published | LAN no; the Linux host itself yes, by container IP | Docker blocks direct routing from outside |
| Host or LAN | Published port -p 8080:80 | Yes, on all host addresses (IPv4 and IPv6) | DNAT in nat DOCKER chain |
| Host | Published -p 127.0.0.1:8080:80 | Host only | DNAT limited to 127.0.0.1, raw-table guard |
| Container | A service on the host | Docker Desktop: host.docker.internal; Linux: --add-host host.docker.internal:host-gateway | Bridge gateway / VM gateway |
The five things to do.
| Situation | Do this |
|---|---|
| Any stack | Put it on a user-defined network (Compose does this for you) and call peers by service name |
| A database, Redis, a queue | Do not publish it. If you must, publish to 127.0.0.1 |
| A server inside a container | Listen on 0.0.0.0 (or ::), never 127.0.0.1 |
| Your own firewall policy for published ports | Put rules in DOCKER-USER (iptables) or your own nftables table, not in ufw/INPUT |
| Large responses hang over a VPN or overlay | Lower the network MTU (--mtu, com.docker.network.driver.mtu) or clamp MSS |
Why it exists
A process on a laptop shares one network stack with every other process: one routing table, one set of ports, one firewall. Two programs that both want port 5432 cannot coexist, and anything one of them does to the stack affects the others. Containers fix that by giving each container its own stack (a network namespace), then rebuilding connectivity on purpose: a virtual cable to a virtual switch, NAT to get out, explicit publishing to get in, and DNS so names replace IPs that change on every restart.
| Without container networking | With it |
|---|---|
| One port space: two Postgres servers need two ports and two configs | Every container listens on its own 5432; the host maps only what you publish |
Services find each other by localhost and fixed ports | Services find each other by name on a shared network |
| Anything on the machine can talk to anything | Networks are isolated by default; you choose who shares a network |
| Changing a firewall affects everything | Docker manages its own chains per network |
| Cost: none | Cost: an extra hop through a bridge, NAT for published ports, a DNS forwarder, and new ways to break (MTU, rule ordering, subnet clashes) |
The everyday picture. An office building. Each office (container) has its own phone with an internal extension (container IP) and its own desk directory (netns). A cable runs from every office to the floor's switchboard (the bridge); one switchboard per floor (network). Offices on the same floor call each other by name through the floor's receptionist (embedded DNS at 127.0.0.11). Calls to the outside go through the building's main line, so outsiders see the building's number (MASQUERADE). Outsiders can only reach an office if the front desk has a rule "calls to the main number, extension 8080, go to office 4" (a published port, DNAT). Offices on different floors cannot call each other unless someone has a phone on both floors.
Three misunderstandings, up front.
| Misunderstanding | Reality |
|---|---|
"EXPOSE 80 in my Dockerfile opens the port" | EXPOSE is documentation. Only -p/ports: publishes; peers on the same network reach every port anyway |
| "ufw blocks 5432, so my published Postgres is safe" | Docker's DNAT happens in the nat table before ufw's INPUT rules; the docs say published ports bypass ufw |
"localhost inside the container is my laptop" | localhost in a container is that container. The host is host.docker.internal (Desktop) or the bridge gateway |
Where it comes from
| Source or release | What it gave us |
|---|---|
Linux network namespaces, veth(4), Linux bridge | The kernel pieces: "A network namespace is logically another copy of the network stack" (ip-netns(8)) |
Legacy links (--link) | The first container-to-container naming on the default bridge; the docs now say links on the default bridge "are deprecated and scheduled for removal in Docker Engine 30.0" and warn from 29.6 |
| User-defined networks (libnetwork) | Per-network bridges, DNS by name, connect/disconnect at runtime, pluggable drivers |
| RFC 7348 (2014), VXLAN | The overlay encapsulation: UDP port 4789, an 8-byte VXLAN header, and "VTEPs MUST NOT fragment VXLAN packets" |
| Docker Engine 28.0.0 (2025-02-19) | Port-publishing rules "extensively modified"; direct routed access to unpublished ports blocked; neighbours can no longer reach ports published to 127.0.0.1; new gw-priority; nat-unprotected and isolated gateway modes |
| Docker Engine 29.0.0 (2025-11-10) | Experimental nftables firewall backend (firewall-backend: nftables); unspecified addresses in --subnet (e.g. 0.0.0.0/24) |
| Docker Desktop 4.34 | Host networking on Desktop as an opt-in setting (L4 only) |
| Compose spec | networks: top-level, internal, external, aliases, network_mode, enable_ipv4 (Compose 2.33.1), extra_hosts with = separator (2.24.1) |
The moby sources for v27.5.1 and v28.0.0 both define IsolationChain1 = "DOCKER-ISOLATION-STAGE-1" and IsolationChain2 = "DOCKER-ISOLATION-STAGE-2", and DOCKER-FORWARD first appears next to them in the v28.1.0 source; the isolation-stage names are what you meet in older blog posts and on older engines. On the 29.8.1 lab engine the filter table had DOCKER, DOCKER-BRIDGE, DOCKER-CT, DOCKER-FORWARD, DOCKER-INTERNAL and DOCKER-USER, and no isolation-stage chains.
The concept catalogue
Network namespaces and veth pairs Must-know
In plain words: Each container gets a private copy of the network stack. A virtual cable (a veth pair) connects that private stack to the host: whatever goes in one end comes out the other.
Common misunderstanding: "A container has a virtual network card emulated by Docker." There is no emulation and no extra kernel: the container's eth0 is one end of a veth pair living in another namespace; packets cross it as fast as a function call.
Definition: network_namespaces(7): namespaces "provide isolation of the system resources associated with networking: network devices, IPv4 and IPv6 protocol stacks, IP routing tables, firewall rules, ... port numbers (sockets)". veth(4): "veth devices are always created in interconnected pairs ... Packets transmitted on one device in the pair are immediately received on the other device." Docker creates a pair per container per network, moves one end into the container's namespace, names it eth0 (eth1, ... for more networks) and plugs the other end into the bridge.
How the lab container's eth0 maps to the host side (the number after @if is the peer's interface index):
$ docker run --rm --net container:dnet-client nicolaka/netshoot ip -d link show eth0 # lab: same command from a local image with iproute2
11: eth0@if302: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ... link-netnsid 0
veth addrgenmode eui64 numtxqueues 8 ... gso_max_size 65536 ...
$ docker exec dnet-client cat /sys/class/net/eth0/iflink
302
$ ip -o link show master br-b3c65fc0dd44 # on the host / in the VM
301: vethd431bb2@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-b3c65fc0dd44 state UP
302: veth5fd4b27@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-b3c65fc0dd44 state UPEvery container's end is ifindex 11 in its own namespace (@if11 on the host side), which is why the host-side names, not the numbers, identify a container. iflink 302 in the container points to veth5fd4b27 on the host.
1 docker run --network dnet-app ... dockerd asks the bridge driver for an endpoint
2 ip link add vethXXXX type veth peer ... pair created in the host namespace
3 one end moved into the container netns renamed eth0, address 172.22.0.3/16, MTU from the network
4 other end: ip link set vethXXXX master br-... plugged into the network's bridge
5 route in the container: default via 172.22.0.1 (the bridge address)
6 /etc/resolv.conf, /etc/hosts written; DNS rules added inside the container netnsReal scenarios: two containers each listening on 5432 without conflict; a tcpdump sidecar that joins a container's namespace to see exactly its traffic; a stuck connection you debug with nsenter --net from the host because the image has no tools; Kubernetes pods, which are the same mechanism with one namespace shared by all containers in the pod (Kubernetes networking).
| Tool | What it does here | Example |
|---|---|---|
ip netns | Named namespaces under /var/run/netns/NAME | Docker keeps its own under /var/run/docker/netns/, so ip netns list is empty unless you link them |
nsenter | Run a command in another process's namespaces | nsenter -t PID -n ip addr (PID from docker inspect -f on .State.Pid) |
docker run --net container:X | Start a tools container inside X's namespace | docker run --rm -it --net container:web nicolaka/netshoot |
ethtool -S vethX | Find a veth peer index | peer_ifindex: 16 (from veth(4)) |
/sys/class/net/eth0/iflink | Peer index from inside the container | 302 in the lab |
Fix / how to use it: never install network tools into production images to debug; enter the namespace instead (see Seeing it).
The bridge: docker0 and br-xxxxxxxxxxxx Must-know
In plain words: A Linux bridge is a software Ethernet switch. Docker makes one per bridge network and gives it the network's gateway address; containers plugged into it talk at layer 2, and the bridge is their way out.
Common misunderstanding: "docker0 is all of Docker's networking." docker0 is only the default network. Every user-defined bridge network gets its own device named br- plus the first 12 characters of the network ID (br-b3c65fc0dd44 for network b3c65fc0dd44... in the lab).
Definition: the bridge has the gateway IP (172.22.0.1/16), a connected route for the subnet, and one port per veth. From the docs: "a bridge network uses a software bridge which lets containers connected to the same bridge network communicate, while providing isolation from containers that aren't connected to that bridge network."
$ docker network create dnet-app
$ docker network inspect dnet-app --format '{{json .IPAM.Config}} driver={{.Driver}} internal={{.Internal}}'
[{"Gateway":"172.22.0.1","Subnet":"172.22.0.0/16"}] driver=bridge internal=false
$ ip -br addr show br-b3c65fc0dd44
br-b3c65fc0dd44 UP 172.22.0.1/16 fe80::30c6:9fff:feb6:177/64
$ ip route | grep br-b3c65fc0dd44
172.22.0.0/16 dev br-b3c65fc0dd44 proto kernel scope link src 172.22.0.1
$ docker exec dnet-client ip route
default via 172.22.0.1 dev eth0
172.22.0.0/16 dev eth0 scope link src 172.22.0.3Real scenarios: "I see 40 br- interfaces on the CI runner" (every Compose project left a network); a corporate VPN route for 172.22.0.0/16 that the new bridge now shadows (IPAM); more than about 1000 containers on one bridge, where the docs warn that "bridge networks become unstable and inter-container communications may break".
Bridge option (-o on docker network create) | Default | Effect |
|---|---|---|
com.docker.network.bridge.name | br- + id | Interface name |
com.docker.network.bridge.enable_ip_masquerade | true | Outbound NAT |
com.docker.network.bridge.enable_icc | true | Inter-container connectivity inside the network |
com.docker.network.bridge.host_binding_ipv4 | all addresses | Default host IP for -p without an IP |
com.docker.network.driver.mtu | 0 (no limit, use the default) | Container MTU |
com.docker.network.bridge.gateway_mode_ipv4/ipv6 | nat | nat, nat-unprotected, routed, isolated |
com.docker.network.bridge.inhibit_ipv4 | false | Do not put the gateway IP on the bridge |
com.docker.network.container_iface_prefix | eth | Interface name prefix inside containers |
Fix / how to use it: docker network prune removes unused networks (and their br- devices and rules); name networks in Compose so you can recognise them.
Default bridge vs user-defined bridge Must-know
In plain words: The network called bridge that containers join when you do not say --network is a legacy leftover: no names, shared by everything. A network you create yourself gives you DNS by name, isolation from other stacks, and per-network settings.
Common misunderstanding: "My two containers are both on a bridge, so ping db should work." Only on a user-defined bridge. The docs: "Containers on the default bridge network can only access each other by IP addresses, unless you use the --link option, which is considered legacy."
Definition (from the bridge driver page): user-defined bridges provide automatic DNS resolution, better isolation ("All containers without a --network specified, are attached to the default bridge network. This can be a risk, as unrelated stacks/services/containers are then able to communicate"), connect/disconnect on the fly, and per-network configuration; the default bridge is configured only through daemon.json (bip, fixed-cidr, mtu, default-gateway, dns) and a daemon restart.
Lab, default bridge:
$ docker run -d --name dnet-legacy1 alpine:3 sleep 3600
$ docker run -d --name dnet-legacy2 alpine:3 sleep 3600
$ docker exec dnet-legacy1 cat /etc/resolv.conf
nameserver 192.168.65.7
# Based on host file: '/etc/resolv.conf' (legacy)
$ docker exec dnet-legacy1 ping -c1 -W1 dnet-legacy2
ping: bad address 'dnet-legacy2'
$ docker exec dnet-legacy1 ping -c1 -W1 172.17.0.8
64 bytes from 172.17.0.8: seq=0 ttl=64 time=0.102 msLab, user-defined bridge:
$ docker exec dnet-client cat /etc/resolv.conf
nameserver 127.0.0.11
options ndots:0
# Based on host file: '/etc/resolv.conf' (internal resolver)
# ExtServers: [host(192.168.65.7)]
$ docker exec dnet-client nslookup dnet-web
Server: 127.0.0.11
Name: dnet-web
Address: 172.22.0.2| Property | Default bridge | User-defined bridge |
|---|---|---|
| Name resolution | None (copy of host resolv.conf) | Embedded DNS at 127.0.0.11: container names, aliases, Compose service names |
| Isolation | All "no --network" containers share it | Only containers you attach |
| Attach/detach at runtime | No (recreate the container) | docker network connect/disconnect |
| Settings | daemon.json, restart Docker | Per network at creation |
--link | Works, deprecated, removal planned for Engine 30.0 | Links not needed |
| Env-var sharing via links | Yes (legacy) | No; use Compose, volumes, secrets |
| Production use | Docs: "not recommended for production use" | Recommended |
Fix / how to use it: in docker run always pass --network; in Compose do nothing (Compose creates PROJECT_default). Compose's network_mode: bridge puts a service back on the default bridge and loses name resolution; avoid it.
Container to outside: MASQUERADE Must-know
In plain words: When a container talks to the internet, the host rewrites the source address to its own, so the other side sees the host, and replies find their way back through conntrack.
Common misunderstanding: "My container has a public IP because curl ifconfig.me from it shows one." That is the host's (or NAT gateway's) address. The container's 172.x address never leaves the host.
Definition: one nat POSTROUTING rule per bridge network: -s SUBNET ! -o BRIDGE -j MASQUERADE (traffic from the subnet leaving through any interface other than its own bridge). Docker also needs IP forwarding (net.ipv4.ip_forward=1); the docs: Docker "enables the sysctl settings net.ipv4.ip_forward and net.ipv6.conf.all.forwarding if they are not already enabled", and when it does so it sets the FORWARD policy to drop.
$ iptables -t nat -S POSTROUTING | grep 172.22 # lab
-A POSTROUTING -s 172.22.0.0/16 ! -o br-b3c65fc0dd44 -j MASQUERADE
$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 11 container 172.22.0.3:41000 -> 93.184.215.14:443 SYN, routed to default gw 172.22.0.1
2 host routing: out via eth0
3 nat POSTROUTING: source in 172.22.0.0/16 and leaving via eth0, not the bridge -> MASQUERADE to host 192.168.65.3:41000 (port kept if free)
4 conntrack stores both tuples
5 reply 93.184.215.14:443 -> 192.168.65.3:41000 matches conntrack, destination restored to 172.22.0.3:41000
6 filter FORWARD: DOCKER-CT accepts RELATED,ESTABLISHED into the bridgeReal scenarios: a payment provider allow-lists your server's IP, and every container on that host shares it; outbound rate limits from an API apply per host, not per container; docker network create -o com.docker.network.bridge.enable_ip_masquerade=false for a network that must route with real addresses; a specific SNAT source with com.docker.network.host_ipv4.
| Knob | Effect |
|---|---|
--ip-masq=false (daemon), enable_ip_masquerade=false (network) | No outbound NAT; you must route the subnet yourself |
com.docker.network.host_ipv4 / host_ipv6 | SNAT to this address instead of MASQUERADE |
gateway_mode_ipv4=routed | No NAT; packets leave with the container address; the network must be routed to the host |
internal: true / --internal | No default route at all: no egress |
Fix / how to use it: to know the address the world sees, ask the world (curl https://ifconfig.me from the container); to control it, use a dedicated egress host/NAT gateway, not per-container tricks.
Outside to container: publishing ports Must-know
In plain words: -p HOST:CONTAINER installs a forward: traffic to a host port is redirected to the container port. Without an IP it listens on every host address, which on a server means the internet.
Common misunderstanding: "EXPOSE 5432 or Compose expose: publishes the port." The Dockerfile reference: "The EXPOSE instruction doesn't actually publish the port. It functions as a type of documentation". And the reverse mistake: "-p 5432:5432 is only for my app on the host." It is for everyone who can reach the host.
Definition: for each published port Docker adds a DNAT rule in the nat DOCKER chain (entered from PREROUTING and OUTPUT for local destinations), an accept rule for the container port in the filter DOCKER chain, and, for 127.0.0.1 bindings, a raw-table rule that drops packets to 127.0.0.1 arriving on any interface other than lo.
Lab: -p 18081:80 and -p 127.0.0.1:18082:80 on the same network:
$ iptables -t nat -S DOCKER
-A DOCKER -p tcp -m tcp --dport 18081 -j DNAT --to-destination 172.22.0.4:80
-A DOCKER -d 127.0.0.1/32 -p tcp -m tcp --dport 18082 -j DNAT --to-destination 172.22.0.5:80
$ iptables -S DOCKER | grep br-b3c65fc0dd44
-A DOCKER -d 172.22.0.5/32 ! -i br-b3c65fc0dd44 -o br-b3c65fc0dd44 -p tcp -m tcp --dport 80 -j ACCEPT
-A DOCKER -d 172.22.0.4/32 ! -i br-b3c65fc0dd44 -o br-b3c65fc0dd44 -p tcp -m tcp --dport 80 -j ACCEPT
-A DOCKER ! -i br-b3c65fc0dd44 -o br-b3c65fc0dd44 -j DROP
$ iptables -t raw -S PREROUTING | grep 18082
-A PREROUTING -d 127.0.0.1/32 ! -i lo -p tcp -m tcp --dport 18082 -j DROPThe diagram has two lanes because the lab proved they differ. Inside the VM (lane A), a container calling the VM address 192.168.65.3:18081 was DNATed, and conntrack shows both tuples:
$ docker exec dnet-legacy1 wget -qO- http://192.168.65.3:18081/ | grep -o "<title>.*</title>"
<title>Welcome to nginx!</title>
$ conntrack -L -p tcp --orig-port-dst 18081
tcp 6 119 TIME_WAIT src=172.17.0.7 dst=192.168.65.3 sport=47502 dport=18081 src=172.22.0.4 dst=172.22.0.1 sport=80 dport=47502 [ASSURED]
$ docker exec dnet-legacy1 wget -qO- -T 3 http://192.168.65.3:18082/ # 127.0.0.1-only publish
wget: can't connect to remote host (192.168.65.3): Connection refusedThe reply tuple (dst=172.22.0.1) shows the request was also source-NATed to the bridge gateway, so nginx logged 172.22.0.1, not the calling container. From the Mac (lane B), the listener is Docker Desktop's backend process and the VM connects straight to the container: conntrack held src=192.168.65.1 dst=172.22.0.4 dport=80 and no entry for 18081 (Desktop's daemon runs with "allow-direct-routing": true and "userland-proxy": false, read from /run/config/docker/daemon.json in the VM).
$ docker port dnet-pub; docker port dnet-publocal
80/tcp -> 0.0.0.0:18081
80/tcp -> [::]:18081
80/tcp -> 127.0.0.1:18082
$ curl -s -o /dev/null -w "%{http_code}\n" http://LAN-IP:18081/ # from the LAN address of the Mac
200
$ curl -s -m 3 -o /dev/null -w "%{http_code}\n" http://LAN-IP:18082/
000 # exit 7: refused
$ lsof -nP -iTCP:18081 -iTCP:18082 -sTCP:LISTEN
COMMAND PID ... TYPE NAME
com.docke 88247 ... IPv6 TCP *:18081 (LISTEN)
com.docke 88247 ... IPv4 TCP 127.0.0.1:18082 (LISTEN)| Flag / Compose | Meaning |
|---|---|
-p 8080:80 / "8080:80" | Host port 8080 on all IPv4 and IPv6 host addresses to container TCP 80 |
-p 127.0.0.1:8080:80 / "127.0.0.1:8080:80" | Host only. Before 28.0.0, hosts on the same L2 segment could still reach it (moby/moby#45610) |
-p '[::1]:8080:80' | IPv6 loopback only |
-p 0.0.0.0:8080:80 | IPv4 only |
-p 8080:80/udp, -p 53:53/tcp -p 53:53/udp | UDP (DNS, QUIC, syslog, WireGuard) must be published separately |
-p 80 / "3000" | Random host port from /proc/sys/net/ipv4/ip_local_port_range; see docker port |
-P / --publish-all | Every EXPOSEd port to a random host port |
--expose 80 / expose: | Metadata only; nothing published |
Long syntax host_ip, published, target, protocol, mode: host|ingress | Same, explicit; mode matters for Swarm |
Daemon "ip": "127.0.0.1" or network host_binding_ipv4 | Change the default bind address |
Real scenarios: a staging Postgres published as 5432:5432 and found by an internet scanner; a laptop on café Wi-Fi exposing a dev Redis; a DNS server container that answers TCP but not UDP because only TCP was published; -P giving a new random port on each restart and breaking a bookmark.
Fix / how to use it: publish only the entry point (reverse proxy), bind admin and data ports to 127.0.0.1 or not at all, and set "default-network-opts": {"bridge": {"com.docker.network.bridge.host_binding_ipv4": "127.0.0.1"}} on developer machines so a forgotten IP is safe.
Container to container: networks, several networks, aliases Must-know
In plain words: Containers on the same user-defined network see every port of each other by name. Containers on different networks see nothing of each other. A container can be on several networks, like a server with several cables.
Common misunderstanding: "To let the web container reach the database I must publish the database port." No: put both on one network and use db:5432. Publishing is for the host and the outside.
Definition: the bridge driver installs rules so that "containers connected to different bridge networks can only communicate with each other using published ports". A container connected to N networks has N interfaces and N addresses; its default gateway is chosen by Docker (override with gw-priority, Engine 28.0+). Aliases are per network.
Lab: isolation, then an alias on a second network:
$ docker network create dnet-other
$ docker run -d --name dnet-other --network dnet-other alpine:3 sleep 3600
$ docker exec dnet-other nslookup dnet-web
*** Can't find dnet-web: No answer
$ iptables -L DOCKER -v -n | grep DROP # before
3 180 DROP 0 -- !br-b3c65fc0dd44 br-b3c65fc0dd44 0.0.0.0/0 0.0.0.0/0
$ docker exec dnet-other wget -qO- -T 3 http://172.22.0.2/
wget: download timed out
$ iptables -L DOCKER -v -n | grep DROP # after: +3 SYN retries dropped
6 360 DROP 0 -- !br-b3c65fc0dd44 br-b3c65fc0dd44 0.0.0.0/0 0.0.0.0/0
$ docker network connect --alias api dnet-other dnet-web
$ docker exec dnet-other wget -qO- -T 3 http://api/ | grep -o "<title>.*</title>"
<title>Welcome to nginx!</title>
$ docker exec dnet-client nslookup api # alias only exists on dnet-other
*** Can't find api: No answer
$ docker inspect dnet-web --format '{{range $k,$v := .NetworkSettings.Networks}}{{$k}} ip={{$v.IPAddress}} aliases={{$v.Aliases}} dnsnames={{$v.DNSNames}}{{println}}{{end}}'
dnet-app ip=172.22.0.2 aliases=[] dnsnames=[dnet-web c2575da723c8]
dnet-other ip=172.23.0.3 aliases=[api] dnsnames=[dnet-web api c2575da723c8]T client (dnet-other) DNS 127.0.0.11 web (dnet-app + dnet-other)
1 wget http://172.22.0.2/ -> SYN routed via 172.23.0.1, filter DOCKER: ! -i br-b3c.. -o br-b3c.. DROP (timeout)
2 docker network connect --alias api dnet-other dnet-web web gets eth1 172.23.0.3
3 lookup api -> answers 172.23.0.3 (only on dnet-other)
4 SYN 172.23.0.x -> 172.23.0.3:80 on the same bridge accepted, no NATReal scenarios: a reverse proxy on frontend and backend, the database only on backend; one Compose project's API joining a shared inter-project network so another project can call it; two replicas sharing one alias (search), where the docs warn "exactly which container the name resolves to is not guaranteed"; after docker compose up recreates a container, the name points to the new IP and "the old address stops working".
| Operation | Command / Compose |
|---|---|
| Attach at create | docker run --network a --network b ... (repeatable) |
| Attach at runtime | docker network connect [--alias x] [--ip 172.30.0.10] NET CTR |
| Choose default gateway | docker run --network name=gwnet,gw-priority=1 --network other ... |
| Alias | Compose networks: {backend: {aliases: [db-primary]}} |
| Fixed address | Compose ipv4_address / ipv6_address (needs a subnet in ipam) |
| Interface name | --driver-opt com.docker.network.endpoint.ifname=en0 (28.0+) |
Fix / how to use it: design networks as trust zones (edge, app, data), attach each service to the fewest networks it needs, and always reconnect by name after errors because IPs change.
Embedded DNS at 127.0.0.11 Must-know
In plain words: On user-defined networks every container's resolver is 127.0.0.11, a small DNS server inside dockerd. It answers container, service and alias names on the networks that container shares, and forwards everything else to the host's DNS servers.
Common misunderstanding: "127.0.0.11 is a process inside my container." Nothing listens there in the image; Docker adds NAT rules inside the container's namespace that redirect port 53 to a socket owned by the daemon.
Definition: the overview page: "Containers that attach to a custom network use Docker's embedded DNS server. The embedded DNS server forwards external DNS lookups to the DNS servers configured on the host. The embedded DNS server address is 127.0.0.11." Upstreams are queried "in order and stops after a successful response or an NXDOMAIN response". There is no IPv6 address for it; 127.0.0.11 works even in IPv6-only containers.
The rules Docker wrote inside dnet-client's namespace (lab):
$ PID=$(docker inspect -f '{{.State.Pid}}' dnet-client)
$ nsenter -t $PID -n iptables -t nat -S
-N DOCKER_OUTPUT
-N DOCKER_POSTROUTING
-A OUTPUT -d 127.0.0.11/32 -j DOCKER_OUTPUT
-A POSTROUTING -d 127.0.0.11/32 -j DOCKER_POSTROUTING
-A DOCKER_OUTPUT -d 127.0.0.11/32 -p tcp -m tcp --dport 53 -j DNAT --to-destination 127.0.0.11:33345
-A DOCKER_OUTPUT -d 127.0.0.11/32 -p udp -m udp --dport 53 -j DNAT --to-destination 127.0.0.11:38686
-A DOCKER_POSTROUTING -s 127.0.0.11/32 -p tcp -m tcp --sport 33345 -j SNAT --to-source :53
-A DOCKER_POSTROUTING -s 127.0.0.11/32 -p udp -m udp --sport 38686 -j SNAT --to-source :53
$ nsenter -t $PID -n ss -lunt
udp UNCONN 0 0 127.0.0.11:38686 0.0.0.0:*
tcp LISTEN 0 4096 127.0.0.11:33345 0.0.0.0:*The same query on the wire, captured on the container's loopback (tcpdump -X), byte for byte:
18:07:09.497486 IP 127.0.0.1.39729 > 127.0.0.11.38686: UDP, length 26
0x0000: 4500 0036 d126 4000 4011 6b84 7f00 0001 IPv4, len 0x36, DF, TTL 64, proto 17 (UDP), src 127.0.0.1
0x0010: 7f00 000b 9b31 971e 0022 fe3f baf8 0120 dst 127.0.0.11, sport 39729, dport 38686 (after DNAT); DNS id 0xbaf8, flags 0x0120 (RD)
0x0020: 0001 0000 0000 0000 0864 6e65 742d 7765 QDCOUNT 1; label len 8 "dnet-we
0x0030: 6200 0001 0001 b", root 00, QTYPE A (1), QCLASS IN (1)
18:07:09.497609 IP 127.0.0.11.53 > 127.0.0.1.39729: 47864 1/0/0 A 172.22.0.2 (50)
0x0010: 7f00 0001 0035 9b31 003a fe57 baf8 8180 sport 53 (after SNAT); same id; flags 0x8180 (response, RD, RA)
0x0030: 6200 0001 0001 0864 6e65 742d 7765 6200 question echoed, answer name "dnet-web"
0x0040: 0001 0001 0000 0258 0004 ac16 0002 TYPE A, CLASS IN, TTL 0x258 = 600 s, RDLENGTH 4, ac.16.00.02 = 172.22.0.21 app: getaddrinfo("redis") -> /etc/hosts (no match) -> resolv.conf: nameserver 127.0.0.11, ndots:0
2 UDP to 127.0.0.11:53 -> container nat OUTPUT DNAT -> dockerd socket 127.0.0.11:38686
3 dockerd: is "redis" a container/service/alias on a network this container shares? yes -> A 172.26.0.3
4 "example.com"? not local -> forward to host resolvers (ExtServers) from the container's namespace
5 internal network? no upstream path -> SERVFAIL ("server misbehaving" in Go)Real scenarios: getaddrinfo ENOTFOUND db because the app runs on the default bridge; a Go service in an internal network that logs lookup example.com on 127.0.0.11:53: server misbehaving; a corporate split-DNS name (*.corp.local) that the host resolves through a VPN but containers do not, until you pass --dns; Alpine/musl images that ignore search lists differently from glibc (DNS for developers).
| Flag / Compose | Effect |
|---|---|
--dns 10.0.0.2 / dns: | Upstream for this container (used by the embedded server on user-defined networks; written to resolv.conf on the default bridge) |
--dns-search corp.local / dns_search: | Search domain for short names |
--dns-opt ndots:2 / dns_opt: | resolv.conf options; Docker writes ndots:0 by default on user-defined networks |
--hostname / hostname: | The container's own name (default: container ID) |
--add-host name=IP / extra_hosts: | Static /etc/hosts lines; host-gateway resolves to the host |
Daemon "dns": [...] | Default upstreams for all containers |
Not supported with --network container:X | --dns, --dns-search, --add-host, --hostname, --publish |
Fix / how to use it: use service names everywhere; if an external name fails only in containers, compare cat /etc/resolv.conf (the ExtServers comment shows the upstream) with the host's; for Go, GODEBUG=netdns=go+1 prints which resolver ran.
Host network mode Important
In plain words: --network host skips all of the above: the container uses the host's interfaces and ports directly. No NAT, no isolation, no port mapping.
Common misunderstanding: "On my Mac, --network host gives the container my Mac's network." On Docker Desktop the "host" is the Linux VM unless you enable the Desktop host-networking feature (4.34+), which works at layer 4 only.
Definition: the docs: "that container's network stack isn't isolated from the Docker host (the container shares the host's networking namespace), and the container doesn't get its own IP-address allocated." -p is ignored with WARNING: Published ports are discarded when using host network mode. Useful "to optimize performance" and when "a container needs to handle a large range of ports".
$ docker run --rm --network host alpine:3 sh -c 'ip -o -4 addr | grep -E " (eth0|lo) "; grep nameserver /etc/resolv.conf'
1: lo inet 127.0.0.1/8 scope host lo
4: eth0 inet 192.168.65.3/24 brd 192.168.65.255 scope global # the Desktop VM, not the Mac
nameserver 192.168.65.7
$ docker run --rm --network host -p 9999:80 alpine:3 true
WARNING: Published ports are discarded when using host network modeReal scenarios: Prometheus node_exporter and packet capture tools; VoIP/RTP servers with thousands of UDP ports; a load-generator that must not pay NAT cost; two replicas that both want port 80 on one host (they cannot); service-name DNS does not work for a network_mode: host service in Compose.
| Platform | --network host means |
|---|---|
| Docker Engine on Linux | The real host namespace, full L2/L3 |
| Docker Desktop without the setting | The VM's namespace |
| Docker Desktop 4.34+ with "Enable host networking" | TCP/UDP forwarded both ways between Mac and container; not below L4; not with Enhanced Container Isolation; Linux containers only |
Swarm --network host | Data on the host's ports; one task per port per node |
Fix / how to use it: prefer a bridge plus -p; use host mode deliberately for tools and for measured performance needs, and bind the service to a specific interface.
None and container modes Important
In plain words: none gives a container a namespace with only loopback. container:X (Compose service:x) puts a container into X's namespace so they share interfaces, IPs and localhost.
Common misunderstanding: "A sidecar needs its own IP to talk to the main container." In container: mode they are one network identity; the sidecar reaches the app on 127.0.0.1, exactly like containers in one Kubernetes pod.
Definition: none: "Within the container, only the loopback device is created." The docs' Redis example: docker run -d --name redis redis --bind 127.0.0.1 then docker run --rm -it --network container:redis redis redis-cli -h 127.0.0.1.
$ docker run --rm --network none alpine:3 ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 ... inet 127.0.0.1/8 scope host lo
2: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN # idle kernel tunnel devices, down
...
$ docker compose --profile debug up -d debug # network_mode: "service:api"
$ docker compose exec debug ip -o -4 addr show
1: lo inet 127.0.0.1/8 scope host lo
11: eth0 inet 172.25.0.2/16 ... # api's addresses
12: eth1 inet 172.26.0.2/16 ...Real scenarios: a PDF renderer or image converter fed through a volume that must never phone home (none); a tcpdump or netshoot sidecar for a container whose image has no shell; a log shipper or TLS terminator that speaks to the app on localhost; a VPN client container that other services route through via network_mode: service:vpn.
Fix / how to use it: network_mode cannot be combined with networks: in Compose; publish ports on the container that owns the namespace.
Overlay networks Good to know
In plain words: An overlay is one virtual network spanning several Docker hosts. Each host wraps container frames in UDP (VXLAN) and sends them to the host where the target container lives.
Common misunderstanding: "Overlay works between any Docker hosts." It requires Swarm mode ("Docker hosts must be part of a swarm to use overlay networks, even when connecting standalone containers") and open ports between nodes.
Definition: VXLAN (RFC 7348) adds outer Ethernet, IP, UDP and an 8-byte VXLAN header (50 bytes on IPv4), so the inner MTU is smaller than the underlay's; --opt encrypted enables IPsec "at the level of the Virtual Extensible LAN" with "a non-negligible performance penalty". --attachable lets standalone containers join. Swarm creates ingress (routing mesh) and docker_gwbridge (the node's way out).
| Port | Purpose |
|---|---|
| 2377/tcp | Swarm control plane (configurable) |
| 4789/udp | VXLAN data path (--data-path-port) |
| 7946/tcp+udp | Node gossip, not configurable |
1 container A (host 1) 10.0.1.5 -> 10.0.1.9 (container B, host 2)
2 host 1 VTEP: wrap frame: outer IP host1 -> host2, UDP dst 4789, VNI of the network
3 underlay network carries a packet 50 bytes bigger than the inner one
4 host 2 VTEP: unwrap, deliver to B's veth on that overlay's bridge (inside a hidden namespace)
5 if the underlay MTU is 1500 and the inner MTU is also 1500: big packets dropped -> see MTUReal scenarios: a small Swarm cluster running a stack across three VMs; standalone containers on two hosts sharing an attachable overlay for a migration; cloud networks that block UDP 4789 between security groups, so services resolve but never connect; the 29.x release note fixing "the MTU of overlay network interfaces being 20 bytes too large when the Swarm data path is IPv6". Docs: overlay networks also "become unstable ... when 1000 containers are co-located on the same host".
Fix / how to use it: open 2377, 4789, 7946 between nodes only; test encryption cost; for anything bigger, Kubernetes with a CNI (Kubernetes networking).
macvlan and ipvlan Good to know
In plain words: Instead of hiding containers behind the host's IP, macvlan makes each container look like a separate machine on your LAN with its own MAC and IP. ipvlan does the same but all containers share the host's MAC.
Common misunderstanding: "The host can talk to its macvlan containers." By default it cannot: "Containers attached to a macvlan network cannot communicate with the host directly, this is a restriction in the Linux kernel."
Definition: docker network create -d macvlan --subnet 192.168.32.0/24 --gateway 192.168.32.254 -o parent=eth0 macnet; parent=eth0.50 creates an 802.1Q sub-interface. Requirements: Linux only (not Docker Desktop), kernel 3.9+ (4.0+ recommended), not rootless, switches that accept many MACs on one port ("promiscuous mode"), and most clouds block it. ipvlan modes: l2 (shared MAC), l3, l3s; flags bridge, private, vepa.
| Aspect | macvlan | ipvlan L2 | ipvlan L3 |
|---|---|---|---|
| MAC per container | Yes | No (parent's) | No |
| Needs promiscuous / MAC-friendly switch | Yes | No | No |
| Host to container | Not by default (add a macvlan sub-interface on the host) | Same restriction | Routed |
| Port publishing / NAT / Docker iptables rules | None ("No rules are created for ipvlan, macvlan or host networking") | None | None |
| Typical | Legacy app with LAN IP licensing, network appliances, Home Assistant | Switches with MAC limits | Underlay routing integration |
Real scenarios: a DHCP-sensitive IoT controller that must answer broadcasts; a licence server bound to a MAC; a home lab giving Pi-hole its own LAN IP; Wi-Fi interfaces, which usually refuse multiple MACs (ipvlan works better).
Fix / how to use it: reserve the container range outside your DHCP pool with --ip-range/--aux-address, and add a host-side macvlan interface if the host must reach the containers.
Docker Desktop on macOS and Windows Must-know
In plain words: On a Mac or Windows PC, Docker runs inside a Linux VM. Everything in this chapter happens inside that VM; your laptop only sees forwarded ports and a few special names.
Common misunderstanding: "I can reach my container at 172.17.0.2 from my Mac." The Desktop docs list it as a known limitation: "There is no docker0 bridge on the host", "I cannot ping my containers", "Per-container IP addressing is not possible".
Definition: "Docker Desktop runs the Docker Engine inside a lightweight Linux virtual machine". Outbound container traffic is NATed inside the VM, carried to the host "over a shared-memory channel", and re-originated by com.docker.backend ("All outbound container network traffic originates from the com.docker.backend process"), so host firewalls and VPN clients see that process. For -p, "Docker Desktop's backend process listens on the specified host port" and forwards into the VM.
| Name | Resolves to | Lab value |
|---|---|---|
host.docker.internal | The host (your Mac/PC) | 192.168.65.254 |
gateway.docker.internal | The VM's gateway | 192.168.65.1 |
| VM address | Where in-VM NAT happens | eth0 192.168.65.3/24 |
| Container upstream DNS | Desktop's resolver | 192.168.65.7 |
| Behaviour | Linux Engine | Docker Desktop |
|---|---|---|
| Who listens on a published port | Kernel DNAT (+ docker-proxy if enabled) | com.docker.backend on the host |
| What a host firewall/EDR sees | Forwarded packets in netfilter | The com.docker.backend process |
docker0 on the host | Yes | No (inside the VM) |
| Reach container IPs from host | Yes (from the host itself) | No |
host.docker.internal | Only with --add-host host.docker.internal:host-gateway | Built in |
--network host | Host namespace | VM, or L4 forwarding with the 4.34+ setting |
| macvlan/ipvlan | Supported | Not supported |
| VPN on the laptop | Container traffic goes where host routing says | Traffic re-originated by the backend, so it follows the host VPN |
Lab detail that matters for security: a port published to 127.0.0.1 on Desktop is still reachable from containers through host.docker.internal, because that name leads to the Mac, where the backend listens on 127.0.0.1:
$ docker run -d --name dnet-pg --network dnet-app -p 127.0.0.1:15432:5432 -e POSTGRES_PASSWORD=pw postgres:16-alpine
$ docker run --rm --network dnet-other -e PGPASSWORD=pw postgres:16-alpine psql -h host.docker.internal -p 15432 -U postgres -Atc "SELECT inet_client_addr()"
172.22.0.1Real scenarios: "works on my Linux CI, not on my Mac" when tests use container IPs; Xdebug or a local Mailpit reached from a container via host.docker.internal; a corporate VPN that blocks container traffic because rules target com.docker.backend; subnet changes in Settings that require resetting Kubernetes and leaving Swarm.
Fix / how to use it: never use container IPs from the host; use published ports and host.docker.internal; on Linux CI add extra_hosts: ["host.docker.internal:host-gateway"] so the same Compose file works everywhere.
Compose networks Must-know
In plain words: docker compose up creates one bridge network per project (PROJECT_default), attaches every service, and registers each service name in DNS. You can declare more networks, mark one internal, or join a network that already exists.
Common misunderstanding: "Services talk to each other on the host port from ports:." The docs: "Networked service-to-service communication uses the CONTAINER_PORT. The host port is only used when accessing the service from outside". db:5432, not db:8001 and not localhost:8001.
Definition: from the Compose networking page: "When you run docker compose up, Compose creates a network named <project-name>_default and attaches all services to it. Each service registers its name with an internal DNS server". internal: true "creates it without a connection to the host's network interfaces. It has no default gateway". external: true means "this network's lifecycle is maintained outside of that of the application" and Compose fails with "Network not found" if it is missing.
The lab Compose file (same file the diagram shows):
# Lab topology: three networks, one public entry point, a data tier with no egress.
# Build the Go tools first (from ../go): GOOS=linux CGO_ENABLED=0 go build -o ../compose/bin/ ./...
# Then: docker compose -p dnet up -d
name: dnet
services:
proxy: # the only published port, and only on loopback
image: nginx:alpine
ports:
- "127.0.0.1:${PROXY_PORT:-8080}:80" # without 127.0.0.1 the port is open to the LAN
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
networks: [edge, app]
depends_on: [api]
api: # reachable as "api" on app, as "api" and "backend" on data
image: alpine:3
command: ["/tools/netinfo", "-listen", ":8080", "redis"]
volumes: ["./bin:/tools:ro"]
expose: ["8080"] # documentation only; peers on app reach 8080 anyway
networks:
app: {}
data:
aliases: [backend]
redis: # no ports: nothing on the host or the LAN can reach it
image: redis:7.4.12-alpine
networks: [data]
worker: # a queue consumer: talks to redis, never to the internet
image: alpine:3
command: ["sleep", "infinity"]
volumes: ["./bin:/tools:ro"]
networks: [data]
debug: # a throwaway sidecar sharing api's network namespace
image: alpine:3
network_mode: "service:api"
command: ["sleep", "infinity"]
profiles: [debug]
networks:
edge: {} # project-scoped name: dnet_edge
app: {}
data:
internal: true # no default route, no NAT, no published ports# nginx resolves "api" through Docker's embedded DNS (127.0.0.11).
# The resolver line + variable makes nginx re-resolve when api is recreated
# and gets a new IP; a bare "proxy_pass http://api:8080" resolves once at start.
server {
listen 80;
resolver 127.0.0.11 valid=10s ipv6=off;
set $upstream http://api:8080;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass $upstream;
}
}What happened when it ran (Go netinfo and conncheck from Solving):
$ docker network ls --filter label=com.docker.compose.project=dnet
NETWORK ID NAME DRIVER SCOPE
6538ebe5c7f1 dnet_app bridge local
382d2aea6cc4 dnet_data bridge local
882daf358ac4 dnet_edge bridge local
$ curl -s http://127.0.0.1:18090/whoami
{"host_header":"127.0.0.1","hostname":"e626c6672159","local_addr":"172.25.0.2:8080","remote_addr":"172.25.0.3:36562","xff":"172.25.0.1"}
$ docker compose exec worker /tools/conncheck redis:6379 api:8080 backend:8080 proxy:80
redis:6379 OK 172.26.0.3:6379 dns=370µs connect=94µs
api:8080 OK 172.26.0.2:8080 dns=156µs connect=63µs
backend:8080 OK 172.26.0.2:8080 dns=99µs connect=41µs
proxy:80 DNS lookup proxy on 127.0.0.11:53: server misbehaving
$ docker compose exec worker /tools/conncheck 1.1.1.1:443
1.1.1.1:443 UNREACH 1.1.1.1:443: dial tcp 1.1.1.1:443: connect: network is unreachableRead the whoami line: the API saw remote_addr 172.25.0.3 (nginx on dnet_app) and nginx put 172.25.0.1 in X-Forwarded-For, the bridge gateway, because the browser's connection arrived through the published port. The worker resolves api and its alias backend on data but not proxy, which shares no network with it, and has no route to the internet. The first attempt to start this file failed on the lab machine with a real port clash, kept here because you will see it too:
Error response from daemon: ports are not available: exposing port TCP 127.0.0.1:8080 -> 127.0.0.1:0: listen tcp4 127.0.0.1:8080: bind: address already in use| Compose key | Level | What it does |
|---|---|---|
networks: (top level) | Project | Declare networks: driver, driver_opts, ipam, internal, external, name, attachable, enable_ipv6, enable_ipv4, labels |
networks: (service) | Service | List, or map with aliases, ipv4_address, ipv6_address, priority/gw_priority, interface_name |
networks.default | Project | Rename or reconfigure PROJECT_default |
external: true + name: | Project | Use an existing network; nothing else allowed |
internal: true | Project | No gateway, no egress; a service on another network too can still go out through that one |
ports: | Service | Publish to the host ("127.0.0.1:8080:80", long syntax with host_ip) |
expose: | Service | Document internal ports; publishes nothing |
network_mode: | Service | host, none, bridge (default bridge, no service DNS), service:NAME, container:ID; excludes networks: |
extra_hosts: | Service | /etc/hosts lines, host.docker.internal:host-gateway |
dns, dns_search, dns_opt | Service | Resolver settings |
--project-name, COMPOSE_PROJECT_NAME, name: | Project | Prefix of every network name |
1 docker compose up -> networks dnet_edge, dnet_app, dnet_data (labels com.docker.compose.*)
2 containers created -> each joins its networks under its service name
3 config change, up again -> api recreated: same name, NEW IP; old connections closed
4 nginx with a fixed upstream -> still sending to the old IP: 502 until nginx restarts
5 nginx with resolver 127.0.0.11 valid=10s and a variable upstream -> re-resolves, recoversReal scenarios: two Compose projects (frontend repo, backend repo) sharing inter-project; a Laravel Horizon worker that must reach Redis but nothing else; Traefik on an external proxy network discovering services from several projects; integration tests in CI running docker compose -p ci-$BUILD_ID so parallel builds get separate networks.
Fix / how to use it: tiers as networks, internal: true for data, external for shared ingress, never hard-coded IPs, and resolve-on-use in proxies.
The iptables and nftables rules Docker writes Must-know
In plain words: Docker owns a set of firewall chains. It puts NAT for publishing and masquerading in the nat table, isolation and "only published ports" in the filter table, and leaves one chain, DOCKER-USER, for your own rules, which run first.
Common misunderstanding: "I'll add iptables -A FORWARD -s 1.2.3.4 -j DROP and it will apply to containers." Rules appended to FORWARD run after Docker's jumps, so already accepted packets never reach them. The docs: "Rules appended to the FORWARD chain will be processed after Docker's rules." And ufw: "Docker routes container traffic in the nat table, which means that packets are diverted before it reaches the INPUT and OUTPUT chains that ufw uses."
Definition: the chains on current engines (the lab ran 29.8.1), from Docker with iptables:
| Table / chain | Role |
|---|---|
filter DOCKER-USER | "A placeholder for user-defined rules that will be processed before rules in the DOCKER-FORWARD and DOCKER chains" |
filter DOCKER-FORWARD | First stage: established traffic and jumps to the other chains |
filter DOCKER-CT | Per-bridge conntrack accept (RELATED,ESTABLISHED) |
filter DOCKER-BRIDGE | Per-bridge jump to DOCKER |
filter DOCKER | Accept published container ports; drop everything else entering the bridge from outside |
filter DOCKER-INTERNAL | Isolation for --internal networks |
filter DOCKER-INGRESS | Swarm routing mesh |
nat DOCKER | DNAT for published ports |
nat POSTROUTING | MASQUERADE per subnet; hairpin rules |
raw PREROUTING | Drop packets addressed to container IPs from outside (direct routing) and to 127.0.0.1 published ports from non-lo interfaces |
(older engines) DOCKER-ISOLATION-STAGE-1/2 | Two-stage isolation between bridge networks; still defined in the v28.1.0 source, absent on 29.8.1 |
The lab's FORWARD chain and the per-network rules:
$ iptables -S FORWARD
-P FORWARD ACCEPT # Docker Desktop VM; a Linux host where Docker enabled forwarding shows -P FORWARD DROP
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-FORWARD
$ iptables -S DOCKER-FORWARD | head -4
-A DOCKER-FORWARD -j DOCKER-CT
-A DOCKER-FORWARD -j DOCKER-INTERNAL
-A DOCKER-FORWARD -j DOCKER-BRIDGE
-A DOCKER-FORWARD -i br-b3c65fc0dd44 -j ACCEPT # one "-i br-X -j ACCEPT" per network: containers may go out
$ iptables -S DOCKER-CT | grep b3c6
-A DOCKER-CT -o br-b3c65fc0dd44 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
$ iptables -S DOCKER-BRIDGE | grep b3c6
-A DOCKER-BRIDGE -o br-b3c65fc0dd44 -j DOCKERThe DOCKER-USER chain on the lab VM was not empty: Docker Desktop installs its own rules there (-i eth0 -j ACCEPT, rules for its services1 interface). On a plain Linux host it starts empty. The FORWARD policy differs for the same reason.
Rules you put in DOCKER-USER, from the docs (replace ext_if):
iptables -I DOCKER-USER -i ext_if ! -s 192.0.2.0/24 -j DROP # only this subnet may reach published ports
iptables -I DOCKER-USER -m state --state RELATED,ESTABLISHED -j ACCEPT # keep replies to containers' own requests
iptables -I DOCKER-USER -p tcp -m conntrack --ctorigdst 198.51.100.2 --ctorigdstport 80 -j ACCEPT # match pre-DNAT addressBecause DNAT already happened, DOCKER-USER sees the container IP and port; match the original with -m conntrack --ctorigdst/--ctorigdstport.
| Daemon option | Effect | Risk |
|---|---|---|
"iptables": false / "ip6tables": false | Docker stops creating most rules | No NAT out, no isolation, "all of their ports will be accessible to hosts on the local network" |
"firewall-backend": "nftables" (29.0+, experimental) | Tables ip docker-bridges / ip6 docker-bridges; no DOCKER-USER, use your own table with base-chain priorities | Not with Swarm in 29.0; Docker no longer enables IP forwarding itself |
"ip-forward-no-drop": true | Do not set FORWARD policy to DROP | Host may act as an open router |
"allow-direct-routing": true | Allow direct routed access to published ports on container IPs | Docker Desktop sets it |
"userland-proxy": false | No docker-proxy processes; hairpin/loopback via NAT | Default is true on Engine |
| firewalld integration | Zone docker (target ACCEPT), policy docker-forwarding | Zone membership is automatic |
Real scenarios: a VPS with ufw "deny incoming" and a published 6379:6379 Redis that is wide open; a reboot flushing hand-written rules that Docker then recreates without yours; iptables-nft vs iptables-legacy mismatch, where the lab VM showed iptables v1.8.9 (nf_tables); migrating DOCKER-USER rules when switching to the nftables backend.
Fix / how to use it: publish less; for remaining public ports, restrict sources in DOCKER-USER (or the cloud security group in front of the host); consider the ufw-docker-style approach only if you understand it; never edit Docker's own chains.
IPv6 Good to know
In plain words: Docker networks are IPv4 by default; you add IPv6 per network (--ipv6) or for the default bridge in daemon.json. Published ports listen on IPv6 host addresses even for IPv4-only networks, through the userland proxy.
Common misunderstanding: "My network is IPv4-only, so nothing reaches it over IPv6." The docs: "Ports on the host's IPv6 addresses will map to the container's IPv4 address if no host IP is given in a port mapping, the bridge network is IPv4-only, and --userland-proxy=true (default)." The lab's docker port showed [::]:18081.
Definition: docker network create --ipv6 --subnet 2001:db8:1234::/64 my-net; without --subnet, Docker picks a ULA prefix (fd00::/8) whose /64 includes "a 40-bit Global ID based on the Docker Engine's randomly generated ID". --ipv4=false gives an IPv6-only network (not for the default bridge). ip6tables (default true) provides the isolation and mapping rules. Gateway mode routed lets IPv6 work without NAT.
| Setting | Where |
|---|---|
--ipv6, --subnet v6, --ipv4=false | docker network create |
"ipv6": true, "fixed-cidr-v6", "bip6" | daemon.json, default bridge only |
enable_ipv6: true, enable_ipv4: false | Compose network |
"default-address-pools" with a v6 base | Automatic v6 subnets |
-o com.docker.network.bridge.gateway_mode_ipv6=routed | No NAT66, direct routing |
| Docker Desktop: Dual / IPv4 only / IPv6 only; DNS filtering of A/AAAA | Settings, Network tab |
Real scenarios: a Go client preferring AAAA records and timing out in containers without IPv6 (Desktop's "DNS resolution behavior" filter exists for this); IPv6-only Kubernetes nodes; exposing a service on IPv6 only by publishing '[::]::80' in routed mode.
Fix / how to use it: decide per network, test both families with curl -4/curl -6, and remember that publishing without an IP covers both.
MTU Important
In plain words: Every link has a maximum packet size. If a link in the middle (a VPN, an overlay, a cloud tunnel) is smaller than what the endpoints think, small requests work and big responses vanish: the connection opens, then hangs.
Common misunderstanding: "If the TCP connection opens and /health works, the network is fine." Handshakes and tiny responses fit in any MTU. The failure only appears when a full-size segment is sent, typically the first large response, a TLS certificate chain or a file download.
Definition: Docker's default bridge MTU is 1500 (--mtu, "mtu" in daemon.json); per network com.docker.network.driver.mtu (default 0 = no limit); for all new networks "default-network-opts": {"bridge": {"com.docker.network.driver.mtu": "1400"}}. VXLAN adds 50 bytes, and RFC 7348 says "VTEPs MUST NOT fragment VXLAN packets". TCP endpoints advertise MSS = MTU - 40 (IPv4) in the SYN; MSS clamping rewrites that on a router.
Lab: two networks joined by a router container, then the router's right leg shrunk to 1400 (offloads were disabled on the server so it sends real 1500-byte frames, as a NIC on a wire does):
# 1. healthy path, every link 1500
$ docker exec dnet-mcli wget -qO /dev/null -T 5 http://10.202.0.10/big.bin && echo big-ok
big-ok
# 2. a 1400-byte link in the middle that drops big frames silently
$ docker exec dnet-router ip link set eth1 mtu 1400
$ docker exec dnet-mcli wget -qO- -T 5 http://10.202.0.10/small.txt
ok
$ docker exec dnet-mcli wget -qO /dev/null -T 5 http://10.202.0.10/big.bin
wget: download timed out
exit=1 after 6s
$ docker cp bin/conncheck dnet-mcli:/conncheck
$ docker exec dnet-mcli /conncheck -get /big.bin 10.202.0.10:80
10.202.0.10:80 STALL 10.202.0.10:80 dns=0s connect=113µs got=254B then silence: check MTU on the path
# 3. fix: clamp the TCP MSS on the router
$ docker exec dnet-router sh -c 'apk add -q iptables && iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu'
$ docker exec dnet-mcli wget -qO /dev/null -T 5 http://10.202.0.10/big.bin && echo big-ok
big-ok
$ tcpdump -i any -nn 'tcp[tcpflags] == tcp-syn' # in the router's namespace
eth0 In IP 10.201.0.10.33530 > 10.202.0.10.80: Flags [S], ... options [mss 1460,...]
eth1 Out IP 10.201.0.10.33530 > 10.202.0.10.80: Flags [S], ... options [mss 1360,...]Two side lessons from building it. First, with TSO/GSO on, the server handed 64 KB super-packets to the veth and the download worked, so lab reproductions of MTU bugs on veth need offloads off. Second, an earlier ping -s 1472 made the router answer "fragmentation needed", the client cached a 1400 path MTU and the next download worked too; the black hole only reproduced from a fresh container. Real black holes are exactly the case where that ICMP never arrives.
$ docker network create -o com.docker.network.driver.mtu=1400 dnet-mtu1400
$ docker run --rm --network dnet-mtu1400 alpine:3 ip link show eth0
11: eth0@if417: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1400 qdisc noqueue state UP| Where the small link is | Typical MTU | Docker-side fix |
|---|---|---|
| A VPN or tunnel on the host (WireGuard, OpenVPN, IPsec) | The tunnel interface's MTU (read it with ip link show) | Network MTU equal to it or lower |
| VXLAN overlay on a 1500 underlay | 1450 (1500 minus RFC 7348's 50 bytes) | Docker sets overlay MTU; check after changes |
| AWS EC2: jumbo frames inside a VPC / outside it | 9001 / 1500 (AWS EC2 MTU docs) | Keep 1500 for internet-bound containers |
| Docker Desktop default bridge (lab VM) | 65535 ("mtu": 65535 in the VM's daemon.json) | The backend re-originates connections, so the Mac's MTU applies outside |
Real scenarios: composer install or apt-get update hanging in a container while the host works (host on VPN with MTU 1420, container at 1500); TLS handshakes stalling at "Server Hello" (the certificate chain is the first big packet); GitLab runners in Docker-in-Docker on a VXLAN-backed cloud; gRPC streams that freeze on large messages only.
Fix / how to use it: measure path MTU (ping -M do -s 1372 host on glibc ping, tracepath), set the Docker network MTU to the smallest link, or clamp MSS on the tunnel endpoint; the troubleshooting playbook covers PMTUD in general.
IP address management and address pools Important
In plain words: Docker hands each network a subnet from a list of pools. If those subnets overlap your VPN, office LAN or cloud VPC, the host routes traffic for those addresses into a Docker bridge instead of the VPN, and remote systems become unreachable.
Common misunderstanding: "Docker only uses 172.17.0.0/16." The built-in pools are 172.17.0.0/16, 172.18.0.0/16, 172.19.0.0/16, 172.20.0.0/14, 172.24.0.0/14, 172.28.0.0/14 in /16 slices and 192.168.0.0/16 in /20 slices; the lab machine had handed out 172.17 to 172.28 already.
Definition: "default-address-pools": [{"base": "10.200.0.0/16", "size": 24}] in daemon.json (256 networks of /24); explicit --subnet, --ip-range, --gateway, --aux-address; fixed container IPs with --ip/--ip6 (only on user-defined networks with a configured subnet); Docker 29.0+ accepts unspecified addresses (--subnet 0.0.0.0/24) to request a size from the pools. Docker "attempts to avoid address prefixes already in use on the host", but only those it can see at creation time.
$ for n in $(docker network ls -q --filter driver=bridge); do docker network inspect -f '{{.Name}} {{range .IPAM.Config}}{{.Subnet}} {{end}}' $n; done
bridge 172.17.0.0/16
dnet-app 172.22.0.0/16
dnet-other 172.23.0.0/16
dnet-internal 172.24.0.0/16
dnet_app 172.25.0.0/16
dnet_data 172.26.0.0/16
dnet_edge 172.27.0.0/16
dnet-mtu1400 172.28.0.0/16
dnet-left 10.201.0.0/24
dnet-right 10.202.0.0/241 09:00 developer connects corporate VPN: routes 172.20.0.0/14 via utun3
2 09:05 docker compose up -> new network takes 172.20.0.0/16 (VPN was down when the pool was checked, or the route is too broad to detect)
3 09:06 git push to gitlab.corp (172.21.4.10) -> host route table: 172.20.0.0/16 dev br-... wins (longer prefix)
4 timeouts to every corporate host in that /16; Docker containers fine
5 fix: default-address-pools outside every corporate range, recreate networksReal scenarios: the classic 172.17/172.18 clash with AWS VPCs or office Wi-Fi in 172.16.0.0/12; running out of networks on a CI runner because every Compose project takes a /16 (switch to size: 24); a Compose file that pins ipv4_address and collides when two copies run on one host.
| Command / key | Use |
|---|---|
docker network create --subnet 10.201.0.0/24 --ip-range 10.201.0.128/25 --gateway 10.201.0.1 | Explicit |
docker run --network dnet-left --ip 10.201.0.254 | Fixed container IP (needs explicit subnet) |
Compose ipam: {config: [{subnet: 10.30.0.0/24}]} + ipv4_address | Same in Compose |
daemon.json bip, fixed-cidr | Default bridge only |
daemon.json default-address-pools | Every new network; restart dockerd, recreate networks |
Fix / how to use it: pick a private range nobody else uses (for example 10.200.0.0/16) for the pools on every developer machine and runner, and keep IPs out of application config.
Performance Good to know
In plain words: A bridge adds a veth hop and, for published ports, NAT; host mode removes both. For most applications the difference is invisible; it matters for packet-per-second heavy services and for proxies handling huge connection counts.
Common misunderstanding: "NAT makes containers slow." The data path is in-kernel; the measurable costs are conntrack table pressure for many short connections, and the userland proxy if traffic goes through it.
Definition: the host-driver page: host mode helps "to optimize performance" because "it doesn't require network address translation (NAT), and no "userland-proxy" is created for each port." The userland proxy (docker-proxy, --userland-proxy, default true on Engine) is a user-space forwarder used for loopback traffic and some IPv6-to-IPv4 mappings; Docker Desktop's VM runs with it off. The DOCKER-USER docs warn that "Using the conntrack extension may result in degraded performance."
| Path | Extra work per packet | When it matters |
|---|---|---|
| Container to container, same bridge | veth + bridge forwarding | Rarely |
| Published port, kernel NAT | DNAT/SNAT, conntrack entry | Many short connections: watch nf_conntrack_max (ports and conntrack) |
| Published port via docker-proxy | User-space copy | High throughput to localhost published ports |
| Host mode | None | UDP-heavy or PPS-heavy services |
| macvlan/ipvlan | No bridge, no NAT | Near-native, with LAN constraints |
| Overlay (VXLAN), encrypted | Encapsulation (+IPsec) | Cross-host throughput, CPU |
Fix / how to use it: measure before switching to host mode (iperf3 between containers vs host), raise conntrack limits on busy NAT hosts, and avoid the userland proxy for heavy loopback traffic.
Security Must-know
In plain words: Docker's defaults are convenient, not hardened: everything on the default bridge can talk to everything else, every port a container listens on is open to its network neighbours, and every published port without an IP is open to the world.
Common misunderstanding: "Containers are isolated, so a compromised container cannot reach my database." If both are on the same network, it can reach every port on it. Isolation is per network, not per container.
Definition: inter-container communication (ICC) is on by default (--icc for the default bridge, com.docker.network.bridge.enable_icc per network); with ICC off, containers on that network cannot talk to each other except through published ports. Since 28.0.0, direct routed access from remote hosts to unpublished container ports is blocked, and loopback-published ports are protected from neighbours.
1 attacker scans the VPS: 6379/tcp open (compose: ports: ["6379:6379"])
2 ufw shows "6379 DENY" -> irrelevant: DNAT in nat PREROUTING, then FORWARD, never INPUT
3 redis has no password -> CONFIG SET dir/dbfilename -> write to a mounted path, or just read sessions
4 fix: remove the ports line (the app reaches redis:6379 on the network), or "127.0.0.1:6379:6379",
plus DOCKER-USER / cloud security group restricting sources| Risk | Control |
|---|---|
| Published DB/cache/admin ports | Do not publish; or bind 127.0.0.1; DOCKER-USER source rules; cloud SG |
| Unrelated containers on the default bridge | User-defined networks per stack; --icc=false on the default bridge |
| Lateral movement inside a stack | Tier networks (internal: true for data), one service per network where possible, enable_icc=false |
| Data exfiltration from workers | internal: true networks; egress proxy for the few that need it |
| Container reaching the cloud instance-metadata address (169.254.169.254) | DOCKER-USER drop to that address for container traffic |
Host services exposed via host.docker.internal / host-gateway | Bind host services to 127.0.0.1 and check what the bridge gateway can reach |
--network host, --privileged, NET_ADMIN | Only for tools; never for app containers |
Fix / how to use it: audit with docker ps --format on .Ports (look for 0.0.0.0: and [::]:), ss -ltnp on the host, and an external port scan of the server's public IP.
Mechanics
Seeing it: inspect, nsenter, tcpdump, netshoot
| Question | Command | Lab output (excerpt) |
|---|---|---|
| Which networks, which subnet | docker network ls, docker network inspect NET | [{"Gateway":"172.22.0.1","Subnet":"172.22.0.0/16"}] |
| Which containers on a network, which IPs | docker network inspect NET (.Containers) | dnet-web 172.22.0.2/16 |
| A container's networks, aliases, DNS names | docker inspect CTR (.NetworkSettings.Networks) | dnsnames=[dnet-web api c2575da723c8] |
| Published ports | docker port CTR | 80/tcp -> 127.0.0.1:18082 |
| Interfaces and routes inside | docker exec CTR ip addr; ip route | default via 172.22.0.1 dev eth0 |
| Same, image without tools | docker run --rm -it --net container:CTR nicolaka/netshoot | full toolset in CTR's namespace |
| Same, from the host | nsenter -t PID -n ip addr | PID from docker inspect (.State.Pid) |
| Host-side bridge ports | ip -o link show master br-ID, bridge link | veth5fd4b27@if11 ... master br-b3c65fc0dd44 |
| NAT and filter rules | iptables -t nat -S, iptables -S, iptables -t raw -S; nft list ruleset | see rules |
| Live flows and NAT mappings | conntrack -L -p tcp --orig-port-dst 18081 | dst=192.168.65.3 dport=18081 ... src=172.22.0.4 sport=80 |
| Packets on the bridge | tcpdump -i br-ID -nn port 80 (host) | IP 192.168.65.1.38612 > 172.22.0.4.80: Flags [S] ... mss 65495 |
| Packets of one container | docker run --net container:CTR IMAGE tcpdump -i eth0 -w /tmp/x.pcap | |
| Docker Desktop VM shell | docker run --rm -it --privileged --pid=host alpine:3 nsenter -t 1 -m -u -n -i sh | iptables v1.8.9 (nf_tables) |
| Daemon network config | /etc/docker/daemon.json; Desktop VM: /run/config/docker/daemon.json | "userland-proxy": false, "mtu": 65535 |
Netshoot's README describes the idea in one line: "you can enter any namespace without modifying what's running inside it". It also shows entering Docker's own network namespaces: mount /var/run/docker/netns into a privileged netshoot and run nsenter --net=/var/run/docker/netns/ID sh (that is where overlay and ingress namespaces live; ip netns list does not show them).
Netfilter order for container traffic
packet from outside to host:18081
raw PREROUTING -> drop if dst is a container IP (direct routing) or 127.0.0.1-published port from !lo
nat PREROUTING -> addrtype LOCAL -> nat DOCKER -> DNAT 172.22.0.4:80
routing decision -> dst is on br-b3c65fc0dd44 -> forward (not INPUT: ufw never sees it)
filter FORWARD -> DOCKER-USER (yours) -> DOCKER-FORWARD -> DOCKER-CT / DOCKER-INTERNAL / DOCKER-BRIDGE -> DOCKER (ACCEPT .4:80)
nat POSTROUTING -> MASQUERADE only if leaving via another interface (or hairpin rule)
bridge -> veth -> container eth0
reply: conntrack matches, reverse NAT applied automatically, DOCKER-CT accepts RELATED,ESTABLISHED
packet from container to internet
container routing -> default via 172.22.0.1 -> host receives on br-...
filter FORWARD -> DOCKER-USER -> DOCKER-FORWARD: -i br-... -j ACCEPT
nat POSTROUTING -> -s 172.22.0.0/16 ! -o br-... -j MASQUERADEWhat each product does
| Product | Bridge implementation | Firewall backend | Published-port listener | DNS for containers | Notes |
|---|---|---|---|---|---|
| Docker Engine on Linux (28/29) | Linux bridge + veth | iptables (default) or nftables (29.0+, experimental) | Kernel DNAT; docker-proxy for loopback/IPv6 when userland proxy is on | 127.0.0.11 on user-defined networks | DOCKER-USER for your rules |
| Docker Desktop for Mac | Same, inside a Linux VM | iptables (nf_tables) in the VM | com.docker.backend on the Mac | 127.0.0.11, upstream 192.168.65.7 | No container IPs from the host; host.docker.internal |
| Docker Desktop for Windows (WSL 2 / Hyper-V) | Same, inside a Linux VM | Same | com.docker.backend.exe | Same | Windows containers use different drivers |
| Docker Desktop for Linux | Same, inside a VM (qemu) | Same | qemu process | Same | Not the same as Engine on Linux |
| Swarm mode | Overlay (VXLAN) + docker_gwbridge, routing mesh ingress | iptables | Every node, mode ingress or host | Service names | 2377, 4789, 7946 |
| Compose | Uses Engine networks with project labels | n/a | Same as Engine | Service names | PROJECT_default |
| Kubernetes | Different model (pods, CNI) | See the chapter | Service / Ingress | Cluster DNS | See Kubernetes networking |
Solving the classic problems
| Problem | Solution | How | Advantage | Cost / limit |
|---|---|---|---|---|
| Peers by name | User-defined network | Compose default, --network | DNS, isolation | None |
| See what a container sees | Go netinfo | Prints interfaces, resolv.conf, hosts, lookups, TCP peer | No tools in the image needed | Static binary to mount |
| Name the failure | Go conncheck / php artisan net:check | DNS, REFUSED, TIMEOUT, UNREACH, STALL | Maps straight to the troubleshooting table | One target at a time |
| "Connection refused" inside Compose | Listen on 0.0.0.0 | bindaddr warning, Octane --host=0.0.0.0 | Obvious in logs | None |
| Data tier exposure | internal: true, no ports: | Compose networks | No route out, nothing in | Needs egress network for services that call out |
| Real client IP behind nginx | trustProxies for the Docker subnets | bootstrap/app.php | Correct logs and rate limits | Must not trust * on public hosts |
| Browser URL vs internal URL | Two settings | APP_URL vs *_INTERNAL_URL | Links correct for both sides | Two values to keep straight |
| MTU black hole | Network MTU or MSS clamp | com.docker.network.driver.mtu, TCPMSS | Fixes all TCP | Must know the smallest link |
Go: what does this container see?
// netinfo prints what a process inside a container can see of its network:
// interfaces with MTU and addresses, the resolver configuration Docker wrote,
// /etc/hosts, and the addresses its peers resolve to. With -listen it also
// serves /whoami, which reports the TCP peer the server actually sees (useful
// to tell a real client from the bridge gateway or a proxy).
//
// go run ./netinfo db redis api.internal
// go run ./netinfo -listen :8080
package main
import (
"bufio"
"context"
"encoding/json"
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
"strings"
"time"
)
func main() {
listen := flag.String("listen", "", "serve /whoami on this address, e.g. :8080")
flag.Parse()
host, _ := os.Hostname()
fmt.Printf("hostname: %s\n", host)
printInterfaces()
printFile("/etc/resolv.conf", func(l string) bool {
return strings.HasPrefix(l, "nameserver") || strings.HasPrefix(l, "search") || strings.HasPrefix(l, "options")
})
printFile("/etc/hosts", func(l string) bool { return l != "" && !strings.HasPrefix(l, "#") })
for _, peer := range flag.Args() {
resolve(peer)
}
if *listen != "" {
http.HandleFunc("/whoami", whoami)
log.Printf("listening on %s", *listen)
log.Fatal(http.ListenAndServe(*listen, nil))
}
}
func printInterfaces() {
ifaces, err := net.Interfaces()
if err != nil {
log.Fatal(err)
}
for _, ifc := range ifaces {
if ifc.Flags&net.FlagUp == 0 {
continue // skip the kernel's idle tunnel devices (tunl0, gre0, sit0...)
}
addrs, _ := ifc.Addrs()
var list []string
for _, a := range addrs {
list = append(list, a.String())
}
fmt.Printf("iface %-6s mtu=%-5d mac=%-17s flags=%-30s addrs=%s\n",
ifc.Name, ifc.MTU, ifc.HardwareAddr, ifc.Flags, strings.Join(list, ","))
}
}
func printFile(path string, keep func(string) bool) {
f, err := os.Open(path)
if err != nil {
fmt.Printf("%s: %v\n", path, err)
return
}
defer f.Close()
s := bufio.NewScanner(f)
for s.Scan() {
if l := strings.TrimSpace(s.Text()); keep(l) {
fmt.Printf("%s: %s\n", path, l)
}
}
}
// resolve uses the pure-Go resolver path, which reads /etc/hosts and then asks
// the nameserver from /etc/resolv.conf (127.0.0.11 on user-defined networks).
func resolve(name string) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
start := time.Now()
addrs, err := net.DefaultResolver.LookupHost(ctx, name)
took := time.Since(start).Round(time.Microsecond)
if err != nil {
fmt.Printf("resolve %-12s FAIL in %v: %v\n", name, took, err)
return
}
fmt.Printf("resolve %-12s -> %s in %v\n", name, strings.Join(addrs, ","), took)
}
func whoami(w http.ResponseWriter, r *http.Request) {
local, _ := r.Context().Value(http.LocalAddrContextKey).(net.Addr)
host, _ := os.Hostname()
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]string{
"hostname": host,
"remote_addr": r.RemoteAddr, // the TCP peer: gateway, proxy or client
"local_addr": fmt.Sprint(local), // which of our addresses was hit
"host_header": r.Host, // what the client typed
"xff": r.Header.Get("X-Forwarded-For"),
})
}Output of /tools/netinfo -listen :8080 redis as the api service in the lab:
hostname: 8ffa056a0bd5
iface lo mtu=65536 mac= flags=up|loopback|running addrs=127.0.0.1/8,::1/128
iface eth0 mtu=1500 mac=6a:ba:83:1c:27:b9 flags=up|broadcast|multicast|running addrs=172.25.0.2/16
iface eth1 mtu=1500 mac=a2:c9:17:51:84:da flags=up|broadcast|multicast|running addrs=172.26.0.2/16
/etc/resolv.conf: nameserver 127.0.0.11
/etc/resolv.conf: options ndots:0
/etc/hosts: 127.0.0.1 localhost
/etc/hosts: 172.25.0.2 8ffa056a0bd5
/etc/hosts: 172.26.0.2 8ffa056a0bd5
resolve redis -> 172.26.0.3 in 798µs
2026/11/25 18:09:05 listening on :8080The Go angle: go doc net says the package can use "a pure Go resolver that sends DNS requests directly to the servers listed in /etc/resolv.conf, or ... a cgo-based resolver"; a CGO_ENABLED=0 binary in scratch or alpine always uses the pure Go one, which reads /etc/hosts and talks to 127.0.0.11 itself. GODEBUG=netdns=go+1 logs the decision. net.Interfaces() reports the MTU you need for the MTU checks, and http.LocalAddrContextKey tells you which of several networks a request arrived on.
Go: the lab's connectivity checker
// conncheck is the lab's connectivity checker. For every target it resolves the
// name, dials TCP and (with -get) downloads a path, then names the failure the
// way the Docker troubleshooting table does:
//
// DNS the name does not resolve (default bridge, wrong network, typo)
// REFUSED the host answered with RST: nothing listens there (app bound to 127.0.0.1?)
// TIMEOUT no answer at all: another network, an internal network, a firewall drop
// STALL connected and got some bytes, then nothing: the classic MTU black hole
//
// go run ./conncheck -get /big.bin web:80 db:5432 example.com:443
package main
import (
"bufio"
"context"
"errors"
"flag"
"fmt"
"io"
"net"
"os"
"strings"
"syscall"
"time"
)
type result struct {
target, verdict, detail string
}
func main() {
timeout := flag.Duration("timeout", 3*time.Second, "per step timeout")
path := flag.String("get", "", "if set, send GET <path> over HTTP/1.1 and read the whole body")
flag.Parse()
if flag.NArg() == 0 {
fmt.Fprintln(os.Stderr, "usage: conncheck [-get /path] host:port ...")
os.Exit(2)
}
failed := false
for _, t := range flag.Args() {
r := check(t, *path, *timeout)
fmt.Printf("%-24s %-8s %s\n", r.target, r.verdict, r.detail)
failed = failed || r.verdict != "OK"
}
if failed {
os.Exit(1)
}
}
func check(target, path string, timeout time.Duration) result {
host, port, err := net.SplitHostPort(target)
if err != nil {
return result{target, "BADARG", err.Error()}
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
t0 := time.Now()
addrs, err := net.DefaultResolver.LookupHost(ctx, host)
if err != nil {
return result{target, "DNS", err.Error()}
}
dnsTook := time.Since(t0).Round(time.Microsecond)
addr := net.JoinHostPort(addrs[0], port)
t1 := time.Now()
conn, err := net.DialTimeout("tcp", addr, timeout)
if err != nil {
return result{target, classify(err), fmt.Sprintf("%s: %v", addr, err)}
}
defer conn.Close()
detail := fmt.Sprintf("%s dns=%v connect=%v", addr, dnsTook, time.Since(t1).Round(time.Microsecond))
if path == "" {
return result{target, "OK", detail}
}
// A tiny HTTP/1.1 client so every byte and every deadline is visible.
fmt.Fprintf(conn, "GET %s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n", path, host)
var total int64
buf := make([]byte, 32*1024)
br := bufio.NewReader(conn)
for {
_ = conn.SetReadDeadline(time.Now().Add(timeout))
n, err := br.Read(buf)
total += int64(n)
if errors.Is(err, io.EOF) {
return result{target, "OK", fmt.Sprintf("%s got=%dB", detail, total)}
}
if err != nil {
var ne net.Error
if errors.As(err, &ne) && ne.Timeout() && total > 0 {
return result{target, "STALL", fmt.Sprintf("%s got=%dB then silence: check MTU on the path", detail, total)}
}
return result{target, classify(err), fmt.Sprintf("%s got=%dB: %v", detail, total, err)}
}
}
}
func classify(err error) string {
var ne net.Error
switch {
case errors.Is(err, syscall.ECONNREFUSED):
return "REFUSED"
case errors.Is(err, syscall.EHOSTUNREACH), errors.Is(err, syscall.ENETUNREACH):
return "UNREACH"
case errors.As(err, &ne) && ne.Timeout():
return "TIMEOUT"
case strings.Contains(err.Error(), "no such host"):
return "DNS"
default:
return "ERROR"
}
}Each verdict is a different row of the troubleshooting table. Real lab outputs: DNS ... server misbehaving from an internal network, UNREACH ... network is unreachable for 1.1.1.1 from the same network, STALL ... got=254B then silence across the 1400-byte link.
Go: bind address
// bindaddr shows the single most common "works locally, refused in Docker" bug.
// A server bound to 127.0.0.1 inside a container only accepts connections from
// inside that same container: the published port, the proxy and every other
// container arrive on eth0 and get RST (connection refused).
//
// LISTEN_ADDR=127.0.0.1:8080 go run ./bindaddr # wrong inside a container
// LISTEN_ADDR=:8080 go run ./bindaddr # all interfaces: right
package main
import (
"fmt"
"log"
"net"
"net/http"
"os"
)
func main() {
addr := os.Getenv("LISTEN_ADDR")
if addr == "" {
addr = ":8080" // all IPv4 and IPv6 addresses of this network namespace
}
host, _, err := net.SplitHostPort(addr)
if err != nil {
log.Fatal(err)
}
if ip := net.ParseIP(host); ip != nil && ip.IsLoopback() && inContainer() {
log.Printf("WARNING: %s is loopback inside a container; -p, nginx and other services cannot reach it", addr)
}
ln, err := net.Listen("tcp", addr)
if err != nil {
// "address already in use" here is the in-container twin of Docker's
// "port is already allocated" on the host side.
log.Fatal(err)
}
log.Printf("listening on %s", ln.Addr())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "hello from %s, you are %s\n", r.Context().Value(http.LocalAddrContextKey), r.RemoteAddr)
})
log.Fatal(http.Serve(ln, nil))
}
// inContainer is a heuristic: Docker creates /.dockerenv in every container.
func inContainer() bool {
_, err := os.Stat("/.dockerenv")
return err == nil
}$ docker run -d --name dnet-bind-bad --network dnet-app -p 127.0.0.1:18083:8080 -e LISTEN_ADDR=127.0.0.1:8080 -v ./bin:/tools:ro alpine:3 /tools/bindaddr
$ docker logs dnet-bind-bad
WARNING: 127.0.0.1:8080 is loopback inside a container; -p, nginx and other services cannot reach it
listening on 127.0.0.1:8080
$ curl -sS http://127.0.0.1:18083/
curl: (52) Empty reply from server # Docker Desktop: the backend accepted, then the VM side failed
$ docker exec dnet-client wget -qO- -T 3 http://dnet-bind-bad:8080/
wget: can't connect to remote host (172.22.0.6): Connection refused
$ curl -sS http://127.0.0.1:18084/ # same binary, LISTEN_ADDR unset (":8080")
hello from 172.22.0.7:8080, you are 172.22.0.1:57922On Docker Desktop the host-side symptom of a loopback-bound server is "Empty reply" or "connection reset", not "refused", because the backend process accepts the connection first; from another container it is a clean Connection refused. The server also logged the bridge gateway 172.22.0.1 as the client for host traffic.
SQL: who is connecting?
-- PostgreSQL: the address the server sees for this session (lab results in comments)
SELECT inet_client_addr(), inet_server_addr();
-- from a container on the same network: 172.22.0.9 | 172.22.0.8
-- via the published port (host.docker.internal:15432): 172.22.0.1 (the bridge gateway)
-- psql inside the db container to 127.0.0.1: 127.0.0.1
-- PostgreSQL pg_hba.conf: the official image ends with "host all all all scram-sha-256";
-- narrow it to the Docker subnets you actually use:
-- host app app 172.26.0.0/16 scram-sha-256
-- MySQL / MariaDB: account hosts match the client address the server sees,
-- which for containers is a 172.x address that changes on every recreate.
CREATE USER 'app'@'172.26.%' IDENTIFIED BY 'secret'; -- data network only
GRANT SELECT, INSERT, UPDATE, DELETE ON shop.* TO 'app'@'172.26.%';
SELECT user, host FROM mysql.user WHERE user = 'app';
SELECT SUBSTRING_INDEX(host, ':', 1) AS client, COUNT(*) FROM information_schema.processlist GROUP BY client;Pin the data network's subnet in Compose (ipam.config.subnet) if you grant by address; otherwise use a strong password and rely on the network tier.
Laravel
The .env for a Laravel app inside Compose. Laravel's shipped config/database.php defaults are env('DB_HOST', '127.0.0.1') and env('REDIS_HOST', '127.0.0.1'), and config/app.php has 'url' => env('APP_URL', 'http://localhost'); inside a container 127.0.0.1 is the container itself, which is why every Sail and Compose setup overrides them (Sail's docs: set DB_HOST to mysql, REDIS_HOST to redis).
# .env for Laravel running inside Compose. Two audiences read these values:
# the PHP process INSIDE the container network, and the BROWSER outside it.
# Browser-facing: what users type and what url()/route() put into HTML, mail and redirects.
APP_URL=http://localhost:8080
# Container-facing: Compose service names, resolved by Docker's embedded DNS (127.0.0.11).
# Laravel's shipped defaults are 127.0.0.1, which inside a container means "this container".
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306 # the CONTAINER port, never the host port from "ports:"
REDIS_HOST=redis
REDIS_PORT=6379
# Service-to-service calls use the internal name, not APP_URL.
BILLING_INTERNAL_URL=http://billing:8000
# Something running on the developer's machine (Mailpit, a local API, Xdebug client).
# Needs extra_hosts: ["host.docker.internal:host-gateway"] on Linux Engine.
MAIL_HOST=host.docker.internal
MAIL_PORT=1025Octane behind an nginx container, with Horizon and the scheduler on an internal data network:
# Laravel 13 + Octane + Horizon in Compose, with network tiers:
# edge : nginx only, the single published port
# app : nginx <-> octane
# data : octane, horizon, scheduler <-> mysql, redis (internal: no egress)
# egress: only the services that must call the internet (mail, payment APIs)
name: shop
x-app: &app
build: .
image: shop-app:latest
env_file: .env
extra_hosts:
- "host.docker.internal:host-gateway" # Linux Engine; Docker Desktop resolves it already
services:
nginx:
image: nginx:alpine
ports:
- "127.0.0.1:8080:80" # put a real reverse proxy or LB in front in production
volumes:
- ./docker/nginx-octane.conf:/etc/nginx/conf.d/default.conf:ro
- ./public:/var/www/html/public:ro
networks: [edge, app]
depends_on: [octane]
octane:
<<: *app
# Must listen on 0.0.0.0: 127.0.0.1 would be unreachable from the nginx container.
command: php artisan octane:start --server=frankenphp --host=0.0.0.0 --port=8000
expose: ["8000"]
networks: [app, data, egress]
horizon:
<<: *app
command: php artisan horizon
networks: [data, egress] # drop egress if no job calls the internet
scheduler:
<<: *app
command: php artisan schedule:work
networks: [data]
mysql:
image: mysql:8.4
environment:
MYSQL_DATABASE: shop
MYSQL_USER: shop
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
volumes: ["mysql:/var/lib/mysql"]
networks: [data] # no "ports:": the database is not on the host
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1"]
interval: 5s
redis:
image: redis:7.4-alpine
networks: [data]
networks:
edge: {}
app: {}
egress: {}
data:
internal: true
volumes:
mysql: {}# nginx in front of Laravel Octane, adapted from the Octane docs for Compose:
# "127.0.0.1:8000" becomes the service name "octane:8000" because nginx and
# Octane now live in different network namespaces.
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_tokens off;
root /var/www/html/public;
index index.php;
# Re-resolve "octane" every 10 s through Docker's embedded DNS so a
# recreated Octane container (new IP) does not leave nginx stuck on the old one.
resolver 127.0.0.11 valid=10s ipv6=off;
set $octane http://octane:8000;
location /index.php { try_files /not_exists @octane; }
location / { try_files $uri $uri/ @octane; }
location @octane {
set $suffix "";
if ($uri = /index.php) { set $suffix ?$query_string; }
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Scheme $scheme;
proxy_set_header SERVER_PORT $server_port;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_pass $octane$suffix;
}
}The Octane docs' nginx example proxies to http://127.0.0.1:8000 because nginx and Octane share one machine there; in Compose they are two namespaces, so it becomes octane:8000 and Octane must start with --host=0.0.0.0 (Sail's own Octane command lines use --host=0.0.0.0).
An artisan command that tests the network from Laravel's side:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use Throwable;
// php artisan net:check --target=billing:8000 --target=api.stripe.com:443
//
// Run it inside the container (docker compose exec octane php artisan net:check)
// to see the network from Laravel's side: what DB_HOST and REDIS_HOST resolve to,
// whether a TCP connection opens, and which Docker mistake a failure points at.
class NetCheckCommand extends Command
{
protected $signature = 'net:check {--target=* : Extra host:port pairs to test} {--timeout=3 : Seconds per step}';
protected $description = 'Resolve and connect to the configured database, Redis and extra targets';
public function handle(): int
{
$timeout = (float) $this->option('timeout');
$targets = [
'db' => config('database.connections.'.config('database.default').'.host').':'
.config('database.connections.'.config('database.default').'.port'),
'redis' => config('database.redis.default.host').':'.config('database.redis.default.port'),
];
foreach ($this->option('target') as $i => $t) {
$targets['extra'.$i] = $t;
}
$rows = [];
$failed = false;
foreach ($targets as $label => $target) {
[$verdict, $detail] = $this->probe($target, $timeout);
$failed = $failed || $verdict !== 'OK';
$rows[] = [$label, $target, $verdict, $detail];
}
// Real client checks on top of raw TCP: authentication and protocol.
$rows[] = ['db (PDO)', DB::connection()->getName(), ...$this->attempt(fn () => DB::connection()->getPdo())];
$rows[] = ['redis (PING)', 'default', ...$this->attempt(fn () => Redis::connection()->ping())];
$this->table(['check', 'target', 'verdict', 'detail'], $rows);
return $failed ? self::FAILURE : self::SUCCESS;
}
/** @return array{0: string, 1: string} */
private function probe(string $target, float $timeout): array
{
[$host, $port] = array_pad(explode(':', $target, 2), 2, null);
if ($host === '127.0.0.1' || $host === 'localhost') {
return ['SUSPECT', 'loopback inside a container is this container; use the Compose service name'];
}
$ips = filter_var($host, FILTER_VALIDATE_IP) ? [$host] : gethostbynamel($host);
if ($ips === false) {
return ['DNS', "{$host} does not resolve: default bridge, wrong network or typo"];
}
$start = microtime(true);
$socket = @fsockopen($ips[0], (int) $port, $errno, $errstr, $timeout);
$ms = round((microtime(true) - $start) * 1000, 1);
if ($socket !== false) {
fclose($socket);
return ['OK', "{$ips[0]} connect={$ms}ms"];
}
// Linux errno values: 111 refused, 110 timed out, 113 no route to host, 101 network unreachable.
return match ($errno) {
111 => ['REFUSED', "{$ips[0]}: nothing listens on {$port} (bound to 127.0.0.1? wrong port?)"],
110, 0 => ['TIMEOUT', "{$ips[0]}: no answer (other network, firewall, internal network)"],
101, 113 => ['UNREACH', "{$ips[0]}: no route (internal network has no egress)"],
default => ['ERROR', "{$ips[0]}: [{$errno}] {$errstr}"],
};
}
/** @return array{0: string, 1: string} */
private function attempt(callable $fn): array
{
try {
$fn();
return ['OK', 'protocol handshake succeeded'];
} catch (Throwable $e) {
return ['ERROR', $e->getMessage()];
}
}
}Trust the proxy containers so $request->ip() and generated URLs are right:
<?php
// bootstrap/app.php (Laravel 13)
//
// Behind the nginx container every request arrives from nginx's address on the
// "app" network (for example 172.25.0.3), so $request->ip() would log nginx,
// rate limits would bucket all users together, and url() would build http://
// links even when the browser used https. Trust only the networks your own
// proxies live on, never "*" on a host whose ports are published to the internet.
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware): void {
$middleware->trustProxies(
// Docker's default address pools: 172.17.0.0/16 to 172.31.0.0/16 and 192.168.0.0/16.
// Narrow this to the subnet you pin in compose.yaml (ipam.config.subnet) when you can.
at: ['172.16.0.0/12', '192.168.0.0/16'],
headers: Request::HEADER_X_FORWARDED_FOR
| Request::HEADER_X_FORWARDED_HOST
| Request::HEADER_X_FORWARDED_PORT
| Request::HEADER_X_FORWARDED_PROTO,
);
})
->withExceptions(function (Exceptions $exceptions): void {
//
})->create();Internal calls use the service name, not APP_URL:
<?php
namespace App\Services;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
// Two URLs for one service, because two networks are involved:
//
// config('app.url') http://localhost:8080 for the browser (links, redirects, mail)
// config('services.billing.internal_url') http://billing:8000 for this container (Compose DNS)
//
// Calling url('/api/...') or APP_URL from inside a container sends the request to
// "localhost", which is this container, not the published port on the host.
//
// config/services.php:
// 'billing' => ['internal_url' => env('BILLING_INTERNAL_URL', 'http://billing:8000')],
class BillingClient
{
public function client(): PendingRequest
{
return Http::baseUrl(config('services.billing.internal_url'))
->connectTimeout(1) // DNS + TCP on a bridge takes well under a millisecond
->timeout(5)
// Retry only when the connection itself failed: a recreated container
// briefly refuses connections before its new IP is in DNS.
->retry(3, 200, fn (\Throwable $e) => $e instanceof \Illuminate\Http\Client\ConnectionException)
->acceptJson();
}
/** @return array<string, mixed> */
public function invoice(int $orderId): array
{
return $this->client()->get("/invoices/{$orderId}")->throw()->json();
}
}The Laravel angle: Horizon "requires that you use Redis to power your queue", so a Horizon container needs the Redis service on a shared network and nothing else; workers that only touch Redis and MySQL belong on the internal data network, which also stops a compromised job from calling out. php artisan octane:start in Compose must bind 0.0.0.0; APP_URL is what the browser uses and goes into links, emails and signed URLs, while service-to-service URLs come from separate config keys.
Troubleshooting
| Symptom | Likely cause | Check | Fix |
|---|---|---|---|
bad address 'db', getaddrinfo ENOTFOUND, no such host | Container on the default bridge, or on a network the target is not on | cat /etc/resolv.conf (127.0.0.11?), docker inspect networks | Same user-defined network; Compose default |
server misbehaving / SERVFAIL for external names | internal: true network, or upstream DNS unreachable | conncheck example.com:443, resolv.conf ExtServers | Add an egress network, or --dns |
Connection refused from another container | App bound to 127.0.0.1, wrong port, app not started | docker exec CTR ss -ltn | Listen on 0.0.0.0; use the container port |
Empty reply from server / reset on a published port (Desktop) | Same as above, seen through the Desktop backend | Logs of the app; ss -ltn inside | Same |
| Timeout to another container's IP | Different networks: DOCKER chain drop | iptables -L DOCKER -v -n counters | Join a shared network |
| Works from host, not from container | Using localhost inside the container to reach a host service | getent hosts host.docker.internal | host.docker.internal (+ host-gateway on Linux) |
| Works in container, not from host (Desktop) | Using the container IP from the Mac | docker port | Publish and use localhost:PORT |
| Small requests fine, large downloads/TLS hang | MTU mismatch on the path (VPN, overlay) | conncheck -get /big, ping -M do -s 1372 | Network MTU, MSS clamping |
port is already allocated / bind: address already in use | Another container or host process on that host port | docker ps --format on .Ports, lsof -iTCP:PORT -sTCP:LISTEN | Change host port; ${PORT:-8080} in Compose |
| DB reachable from the internet | Published without IP; ufw bypassed | External scan; docker ps showing 0.0.0.0:5432 | Remove ports:, bind 127.0.0.1, DOCKER-USER/SG |
Corporate hosts unreachable after compose up | Docker subnet overlaps VPN/LAN | ip route get CORP_IP shows br- | default-address-pools, recreate networks |
App logs every client as 172.x.0.1 | Traffic arrives via the bridge gateway / proxy | whoami endpoint | trustProxies, PROXY protocol on the LB |
| Name resolves to an old IP after redeploy | Long-lived client or nginx cached resolution | nginx resolver, client reconnect | Resolve per connection; resolver 127.0.0.11 valid=10s |
| Containers lost internet after a firewall change | iptables: false, rule flush, or FORWARD policy | iptables -t nat -S POSTROUTING | Restart dockerd; do not flush Docker chains |
Network not found on compose up | external: true network missing | docker network ls | docker network create NAME first |
Choosing
| Situation | Recommendation | Extra technique | Reason |
|---|---|---|---|
| Single host, normal app stack | User-defined bridge (Compose default) | Tier networks, internal: true for data | DNS, isolation, NAT out |
| Developer laptop | Compose + 127.0.0.1 publishing | default-network-opts host binding 127.0.0.1 | Café Wi-Fi safety |
| Reverse proxy in front of several projects | External shared network | Traefik/nginx on it, services join with aliases | One entry point |
| Packet tools, monitoring agents | host | Read-only, minimal capabilities | Need the host stack |
| Thousands of ports, VoIP, game servers | host (or macvlan) | Bind to a specific interface | NAT per port is impractical |
| Batch job with no network | none | Volume in, volume out | Zero exfiltration surface |
| Debug a running container | container: / service: sidecar | netshoot, tcpdump to pcap | No change to the image |
| Container must be a LAN device | macvlan (or ipvlan if MAC-limited) | Host-side macvlan for host access | Own LAN IP |
| Several Docker hosts, no Kubernetes | Swarm overlay | --attachable, encrypted if untrusted underlay | Built in |
| Anything larger | Kubernetes | CNI + NetworkPolicy | Scheduling, policy, ecosystem |
| Host on VPN or tunnel | Bridge with lowered MTU | MSS clamp | Avoid black holes |
| Company with 172.16/12 everywhere | Custom default-address-pools | Same on every runner | Avoid route clashes |
In architecture: from a single process to a distributed system
Monolith (one process, one database)
A Laravel monolith in Compose: nginx (published 127.0.0.1:8080 in dev, behind a cloud load balancer in production), octane, mysql, redis. One user-defined network is enough to start; the database is never published, the app uses DB_HOST=mysql, and APP_URL is the browser URL. The first networking decisions are already architectural: which ports are published (one), which names the app depends on (service names, not IPs), and where the client IP is restored (trustProxies).
Modular monolith
Modules stay in one process, but supporting pieces multiply: Horizon workers, a scheduler, Meilisearch, a mail catcher. Networks become trust zones rather than one flat LAN: edge (nginx), app (nginx, octane), data (internal: true: octane, horizon, mysql, redis). Workers that only need Redis and MySQL live on data only. A second database for a module is another service on data, with its own credentials and, if needed, its own network so other modules cannot even connect.
Microservices
Each service is its own Compose project or deployment with its own default network, and they meet on an external network (docker network create inter-service, external: true), on Swarm overlays, or in Kubernetes. A request flow: browser to gateway (published 443) to orders:8080 (alias on inter-service) to billing:8000 (internal URL from config, not APP_URL), while each service's database stays on that service's private network. What does not survive the boundary: localhost assumptions, fixed IPs, and shared Redis by accident. Names must resolve on the right network, every call needs timeouts and retries on connection errors (a recreated container refuses briefly), and observability needs the original client IP passed in headers (service mesh and sidecars).
Distributed data: replicas, caches, multi-host
Across hosts the bridge is gone: Swarm uses VXLAN overlays (MTU lower by 50 bytes, UDP 4789 open between nodes, encryption optional), Kubernetes uses a CNI. A primary database and its replica on different hosts talk over the overlay or over host networking with published ports; replication streams are exactly the large, long-lived flows that MTU mistakes break. Caches (Redis) close to the app should share a network with it, not be reached via published ports on another host. Address planning matters: overlay subnets, bridge pools, VPC and VPN ranges must not overlap anywhere a packet might travel.
Scaling path
| Load | Networking change |
|---|---|
| 1x: one host, Compose | User-defined networks, one published entry point, internal data network |
| 10x: a few hosts | Load balancer in front of several hosts; each host publishes the app port only to the LB's subnet (DOCKER-USER or security group); shared Redis/MySQL on dedicated hosts reached over private network |
| 100x: many hosts | Orchestrator (Kubernetes or Swarm), overlay/CNI networking, NetworkPolicy instead of hand-written rules, conntrack and MTU tuned on nodes, address plan per cluster |
| Heavy UDP / PPS | Host networking or macvlan for those services only |
Lab
All commands ran on Docker Desktop (engine 29.8.1). On Linux, run the "in the VM" commands directly with sudo. Names start with dnet- so cleanup is one line.
Setup
docker network create dnet-app
docker run -d --name dnet-web --network dnet-app nginx:alpine
docker run -d --name dnet-client --network dnet-app alpine:3 sleep 3600
docker run -d --name dnet-pub --network dnet-app -p 18081:80 nginx:alpine
docker run -d --name dnet-publocal --network dnet-app -p 127.0.0.1:18082:80 nginx:alpine
docker run -d --name dnet-legacy1 alpine:3 sleep 3600 # default bridge, used in experiments 1 and 2
docker run -d --name dnet-legacy2 alpine:3 sleep 3600
# a shell on the host side (Docker Desktop VM):
docker run --rm -it --privileged --pid=host alpine:3 nsenter -t 1 -m -u -n -i shExperiment 1: veth, bridge and DNS. Run docker exec dnet-client cat /sys/class/net/eth0/iflink (lab: 302), then in the VM ip -o link show master br-ID and find the same index (302: veth5fd4b27@if11 ... master br-b3c65fc0dd44). docker exec dnet-client nslookup dnet-web answers from 127.0.0.11 with 172.22.0.2. Repeat with two containers on the default bridge: ping: bad address.
Experiment 2: the rules. In the VM: iptables -t nat -S | grep -E "DOCKER|br-ID" shows the MASQUERADE line and the two DNAT lines (one with -d 127.0.0.1/32); iptables -S DOCKER shows the accept rules and the final DROP; iptables -t raw -S PREROUTING shows -d 127.0.0.1/32 ! -i lo ... --dport 18082 -j DROP. Then docker exec dnet-legacy1 wget -qO- http://192.168.65.3:18081/ works and conntrack -L -p tcp --orig-port-dst 18081 shows the DNAT; the same to :18082 gets Connection refused.
Experiment 3: isolation and multi-network. docker network create dnet-other, start dnet-other on it, wget to 172.22.0.2 times out while the DOCKER DROP counter grows (3 to 6 packets in the lab). docker network connect --alias api dnet-other dnet-web; http://api/ now works from dnet-other but api does not resolve from dnet-client.
Experiment 4: internal network.
$ docker network create --internal dnet-internal
$ docker run --rm --network dnet-internal alpine:3 sh -c 'ip route; wget -qO- -T 3 http://example.com/; echo exit=$?'
172.24.0.0/16 dev eth0 scope link src 172.24.0.2 # no default route
wget: bad address 'example.com'
exit=1
$ docker run --rm --network dnet-internal alpine:3 nslookup example.com
** server can't find example.com: SERVFAIL
$ docker run --rm --network dnet-internal alpine:3 sh -c 'wget -qO- -T 3 http://1.1.1.1/; echo exit=$?'
wget: can't connect to remote host (1.1.1.1): Network unreachable
exit=1DNS fails first (the embedded server has no upstream path), and by IP there is no route at all.
Experiment 5: MTU black hole. Build the left/right networks and the router:
docker network create --subnet 10.201.0.0/24 dnet-left
docker network create --subnet 10.202.0.0/24 dnet-right
docker run -d --name dnet-router --cap-add NET_ADMIN --sysctl net.ipv4.ip_forward=1 --network dnet-left --ip 10.201.0.254 alpine:3 sleep infinity
docker network connect --ip 10.202.0.254 dnet-right dnet-router
docker run -d --name dnet-msrv --cap-add NET_ADMIN --network dnet-right --ip 10.202.0.10 nginx:alpine
docker exec dnet-msrv sh -c 'ip route add 10.201.0.0/24 via 10.202.0.254 && head -c 200000 /dev/urandom > /usr/share/nginx/html/big.bin && echo ok > /usr/share/nginx/html/small.txt'
docker run --rm --net container:dnet-msrv --cap-add NET_ADMIN alpine:3 sh -c 'apk add -q ethtool && ethtool -K eth0 tso off gso off sg off'
docker run -d --name dnet-mcli --cap-add NET_ADMIN --network dnet-left --ip 10.201.0.10 alpine:3 sleep infinity
docker exec dnet-mcli ip route add 10.202.0.0/24 via 10.201.0.254Then follow the MTU block: big download OK, ip link set eth1 mtu 1400 on the router, small OK and big times out after about 6 s, MSS clamp, big OK again, tcpdump shows mss 1460 in and mss 1360 out. Do not run ping -s 1472 before the stall test; it teaches the client the path MTU and hides the bug.
Experiment 6: loopback publishing and bind addresses. From the Mac's LAN address, curl http://LAN-IP:18081/ returns 200 and :18082 fails (000, exit 7); lsof shows com.docker.backend on *:18081 and 127.0.0.1:18082. Then run the bindaddr pair from Go: bind address: the loopback-bound one is refused from a peer container and gives "Empty reply" through Desktop.
Experiment 7: Compose tiers. Build the Go tools (cd docs/snippets/foundations/docker-networking/go && GOOS=linux CGO_ENABLED=0 go build -o ../compose/bin/ ./...), then PROXY_PORT=18090 docker compose up -d in the compose folder; curl http://127.0.0.1:18090/whoami; docker compose exec worker /tools/conncheck redis:6379 api:8080 backend:8080 proxy:80 1.1.1.1:443 gives OK, OK, OK, DNS, UNREACH.
Cleanup
docker compose -p dnet down
docker rm -f $(docker ps -aq --filter name=dnet-)
docker network rm $(docker network ls -q --filter name=dnet-)Common misconceptions
| Belief | Reality |
|---|---|
EXPOSE publishes a port | Documentation only; -p/ports: publishes |
| Containers on the default bridge resolve each other by name | Only on user-defined networks (or legacy --link, deprecated) |
| ufw protects published ports | DNAT runs before INPUT; use DOCKER-USER or an external firewall |
-p 5432:5432 is only for local tools | It listens on all host addresses, IPv4 and IPv6 |
127.0.0.1 in a container is the host | It is the container; use host.docker.internal |
| Compose services call each other on host ports | They use container ports on the shared network |
| Container IPs are stable | They change on recreate; use names |
internal: true only blocks inbound | It removes the default gateway: no egress, no external DNS |
| Host networking on a Mac uses the Mac's interfaces | It uses the VM unless the 4.34+ feature is on, and then only L4 |
| Overlay networks work between any two Docker hosts | They need Swarm and ports 2377, 4789, 7946 |
| The host can always reach macvlan containers | Not by default; kernel restriction |
If /health works, the network is fine | MTU problems only show on large packets |
| Disabling Docker's iptables makes things safer | It removes isolation and NAT; ports become reachable from the LAN |
DOCKER-ISOLATION-STAGE-1 is where isolation lives | Only on older engines; on 29.8.1 it is DOCKER-FORWARD, DOCKER-BRIDGE and the per-bridge DOCKER drop rules |
Cheat sheet
| Topic | Remember |
|---|---|
| Building blocks | netns per container, veth pair, bridge per network, NAT out, DNAT in |
| Default bridge | Legacy: no DNS, shared; configure in daemon.json |
| User-defined bridge | DNS at 127.0.0.11, isolation, connect/disconnect live |
| Publish | -p [IP:]HOST:CONTAINER[/udp]; no IP = world; 127.0.0.1: = host only |
EXPOSE / expose: | Metadata; -P publishes exposed ports to random host ports |
| Name resolution | Container name, Compose service name, aliases, only on shared networks |
| Host service from container | host.docker.internal (Desktop), --add-host host.docker.internal:host-gateway (Linux) |
| Isolation | Different networks cannot talk; one container may join several |
internal: true | No gateway, no egress, no external DNS |
| Your firewall rules | DOCKER-USER (iptables), own table (nftables); match pre-DNAT with --ctorigdst |
| Chains (29.x) | DOCKER-USER, DOCKER-FORWARD, DOCKER-CT, DOCKER-BRIDGE, DOCKER, DOCKER-INTERNAL; nat DOCKER; raw guard |
| MTU | --mtu, com.docker.network.driver.mtu; VXLAN -50; symptom: big responses hang |
| Address pools | default-address-pools away from VPN/VPC ranges; size: 24 for many networks |
| Debug | docker network inspect, nsenter -t PID -n, --net container:X nicolaka/netshoot, tcpdump, conntrack -L |
| Desktop | Everything is in a VM; com.docker.backend listens and egresses; no container IPs from host |
Self-check: questions & answers
- Must-know asked in almost every interview
- Important frequent; expected at senior level
- Good to know extra depth that sets you apart
1 — Two containers started with plain docker run cannot ping each other by name. Why, and what are two fixes? Must-know
Answer
Answer: They are on the default bridge, which has no embedded DNS. Create a user-defined network and attach both (or use Compose); the legacy fix, --link, is deprecated.
2 — A Compose file publishes "6379:6379" for Redis on a VPS with ufw denying 6379. Is Redis reachable from the internet? Must-know
Answer
Answer: Yes. Docker's DNAT in nat PREROUTING forwards the packet through FORWARD, never INPUT, so ufw's rules are not consulted. Remove the port or bind 127.0.0.1, and restrict with DOCKER-USER or a cloud security group.
3 — What exactly does EXPOSE 8080 change? Must-know
Answer
Answer: Image metadata, shown by inspect, and the set of ports -P publishes. It opens nothing; peers on the same network reach every port regardless.
4 — Your Go service logs lookup example.com on 127.0.0.11:53: server misbehaving but redis resolves. What network setting explains it? Important
Answer
Answer: The container is only on an internal: true network: the embedded DNS answers local names but cannot forward to upstream servers, and there is no route out anyway.
5 — Where do you put a rule that only lets 192.0.2.0/24 reach published ports, and why there? Important
Answer
Answer: In DOCKER-USER, which FORWARD jumps to before Docker's own chains; rules appended to FORWARD run after Docker has already accepted the packet. With the nftables backend, in your own table with a base chain at a suitable priority.
6 — A download through a container works on Wi-Fi and hangs when the laptop is on the company VPN; /health works in both cases. Diagnosis and fix? Good to know
Answer
Answer: MTU black hole: the VPN link is smaller than 1500 and the large packets are dropped without ICMP. Lower the network MTU (com.docker.network.driver.mtu or daemon mtu) to the VPN MTU, or clamp MSS.
7 — On a Mac, why can you not reach 172.22.0.2 from the terminal, and what do you use instead? Important
Answer
Answer: The bridge lives in Docker Desktop's Linux VM; the Mac has no route to it. Publish a port and use localhost:PORT; from containers to the Mac, use host.docker.internal.
8 — After docker compose up recreated api, nginx returns 502 until it is restarted. Why, and how do you prevent it? Important
Answer
Answer: nginx resolved api once at start and kept the old IP. Use resolver 127.0.0.11 valid=10s with a variable in proxy_pass so it re-resolves.
9 — Your corporate GitLab at 172.20.4.10 became unreachable after starting a new Compose project. What happened? Good to know
Answer
Answer: Docker allocated 172.20.0.0/16 for the new network, and the host now routes that range to a local bridge. Set default-address-pools to a range not used by the company and recreate the networks.
10 — A Laravel app in Compose uses DB_HOST=127.0.0.1 and fails with "Connection refused". Explain and fix. Must-know
Answer
Answer: 127.0.0.1 inside the PHP container is the PHP container; MySQL runs in another namespace. Use the service name, DB_HOST=mysql, and the container port 3306.
11 — What is the difference between --network host on Linux Engine and on Docker Desktop 4.34+ with host networking enabled? Good to know
Answer
Answer: On Linux it is the real host namespace with full L2/L3. On Desktop it forwards TCP and UDP between the Mac and the container at layer 4 only, and processes cannot bind to the Mac's IP addresses.
12 — Which chains replaced DOCKER-ISOLATION-STAGE-1/2, and where is cross-network traffic dropped now? Good to know
Answer
Answer: On current engines (29.8.1 in the lab): DOCKER-FORWARD, DOCKER-CT, DOCKER-BRIDGE, DOCKER-INTERNAL; traffic entering a bridge from another interface reaches the per-bridge DOCKER rules and is dropped unless it targets a published port.
Glossary
| Term | Meaning |
|---|---|
| Network namespace (netns) | A separate copy of the kernel network stack: interfaces, routes, firewall, ports |
| veth pair | Two linked virtual Ethernet devices; one end in the container, one on the bridge |
ip netns / nsenter | Tools to list/enter network namespaces |
| Linux bridge | Software L2 switch; docker0 for the default network, br-ID for others |
| Default bridge | The legacy bridge network: no DNS, shared by all containers without --network |
| User-defined bridge | A bridge network you (or Compose) create: DNS, isolation, per-network options |
--link | Legacy name/env sharing on the default bridge; deprecated, removal planned for Engine 30.0 |
| MASQUERADE | SNAT to the outgoing interface's address; how containers reach the internet |
| SNAT / DNAT | Rewrite of source / destination address; DNAT implements -p |
| conntrack | Kernel table of flows that makes NAT reversible |
Publish (-p) | Map a host address/port to a container port |
--publish-all (-P) | Publish every exposed port to a random host port |
EXPOSE / expose: | Port metadata; publishes nothing |
| Embedded DNS | dockerd's resolver at 127.0.0.11 for user-defined networks |
ndots | resolv.conf option deciding when a name is tried as absolute; Docker writes ndots:0 |
| Alias | Extra DNS name for a container on one network |
host network | Container shares the host's namespace |
none network | Loopback only |
container: / service: mode | Join another container's namespace (sidecar) |
| Overlay | Multi-host network over VXLAN; requires Swarm |
| VXLAN | L2-in-UDP encapsulation, UDP 4789, 50 bytes overhead on IPv4 |
| macvlan | Container gets its own MAC and LAN IP on a parent interface |
| ipvlan | Like macvlan but shares the parent MAC (L2) or routes (L3) |
| Promiscuous mode | NIC accepting frames for MACs other than its own; needed by macvlan |
host.docker.internal | Name for the host; built into Desktop, host-gateway on Linux |
com.docker.backend | Docker Desktop's host process that forwards ports and egress |
internal: true | Network without gateway or egress |
external: true | Compose uses an existing network it does not manage |
DOCKER-USER | iptables chain for your rules, evaluated before Docker's |
DOCKER-FORWARD, DOCKER-CT, DOCKER-BRIDGE, DOCKER-INTERNAL | Current filter chains for forwarding, conntrack, per-bridge and internal-network rules |
DOCKER-ISOLATION-STAGE-1/2 | Older isolation chains (v27 and early v28 sources) |
| Raw-table guard | Drops direct-routed packets to containers and to loopback-published ports from other interfaces |
iptables: false | Daemon option stopping most rule creation; breaks NAT and isolation |
| nftables backend | firewall-backend: nftables, experimental in 29.x |
| ufw | Ubuntu's firewall frontend; bypassed by published ports |
firewalld docker zone | Zone Docker creates for its bridges, target ACCEPT |
| ICC | Inter-container communication; --icc, enable_icc |
userland proxy / docker-proxy | User-space forwarder for published ports (loopback, IPv6 to IPv4) |
| Gateway mode | nat, nat-unprotected, routed, isolated per address family |
| Direct routing | Reaching a container IP from outside without NAT; blocked by default |
allow-direct-routing | Daemon option permitting direct routing to published ports |
| MTU | Largest packet a link carries; Docker --mtu, com.docker.network.driver.mtu |
| MSS / MSS clamping | Largest TCP payload; rewriting it in SYNs to fit a smaller path |
| IPAM | IP address management: subnets, ranges, gateways, fixed IPs |
default-address-pools | Daemon pools from which network subnets are allocated |
gw-priority | Chooses which network supplies a container's default gateway |
| ULA | IPv6 unique local addresses (fd00::/8), Docker's automatic v6 subnets |
docker_gwbridge / ingress | Swarm's per-node bridge and routing-mesh overlay |
| netshoot | Container image of network tools for namespace debugging |
References
- Docker docs, Networking overview: https://docs.docker.com/engine/network/
- Docker docs, Network drivers: https://docs.docker.com/engine/network/drivers/
- Docker docs, Bridge network driver: https://docs.docker.com/engine/network/drivers/bridge/
- Docker docs, Host network driver: https://docs.docker.com/engine/network/drivers/host/
- Docker docs, None network driver: https://docs.docker.com/engine/network/drivers/none/
- Docker docs, Overlay network driver: https://docs.docker.com/engine/network/drivers/overlay/
- Docker docs, Macvlan network driver: https://docs.docker.com/engine/network/drivers/macvlan/
- Docker docs, IPvlan network driver: https://docs.docker.com/engine/network/drivers/ipvlan/
- Docker docs, Packet filtering and firewalls: https://docs.docker.com/engine/network/packet-filtering-firewalls/
- Docker docs, Docker with iptables: https://docs.docker.com/engine/network/firewall-iptables/
- Docker docs, Docker with nftables: https://docs.docker.com/engine/network/firewall-nftables/
- Docker docs, Port publishing and mapping: https://docs.docker.com/engine/network/port-publishing/
- Docker docs, Use IPv6 networking: https://docs.docker.com/engine/daemon/ipv6/
- Docker docs, Legacy container links: https://docs.docker.com/engine/network/links/
- Docker docs,
docker container runreference: https://docs.docker.com/reference/cli/docker/container/run/ - Docker docs,
docker network createreference: https://docs.docker.com/reference/cli/docker/network/create/ - Docker docs,
dockerdreference: https://docs.docker.com/reference/cli/dockerd/ - Docker docs, Dockerfile reference (EXPOSE): https://docs.docker.com/reference/dockerfile/
- Docker docs, Networking in Compose: https://docs.docker.com/compose/how-tos/networking/
- Compose file reference, Networks: https://docs.docker.com/reference/compose-file/networks/
- Compose file reference, Container specification (network_mode, networks, extra_hosts): https://docs.docker.com/reference/compose-file/container-spec/
- Compose file reference, Workload specification (ports, expose): https://docs.docker.com/reference/compose-file/workload-spec/
- Docker Desktop, Networking overview: https://docs.docker.com/desktop/features/networking/
- Docker Desktop, Networking how-tos: https://docs.docker.com/desktop/features/networking/networking-how-tos/
- Docker Engine 28 release notes: https://docs.docker.com/engine/release-notes/28/
- Docker Engine 29 release notes: https://docs.docker.com/engine/release-notes/29/
- moby v27.5.1 source, bridge iptables setup (isolation chains): https://raw.githubusercontent.com/moby/moby/v27.5.1/libnetwork/drivers/bridge/setup_ip_tables_linux.go
- veth(4): https://man7.org/linux/man-pages/man4/veth.4.html
- network_namespaces(7): https://man7.org/linux/man-pages/man7/network_namespaces.7.html
- ip-netns(8): https://man7.org/linux/man-pages/man8/ip-netns.8.html
- bridge(8): https://man7.org/linux/man-pages/man8/bridge.8.html
- RFC 7348, VXLAN: https://www.rfc-editor.org/rfc/rfc7348.txt
- nicolaka/netshoot README: https://github.com/nicolaka/netshoot
- Go
netpackage documentation (package comment, alsogo doc net): https://go.dev/src/net/net.go - Laravel 13 Octane: https://laravel.com/docs/13.x/octane
- Laravel 13 Horizon: https://laravel.com/docs/13.x/horizon
- Laravel 13 Sail: https://laravel.com/docs/13.x/sail
- Laravel 13 Requests (trusted proxies): https://laravel.com/docs/13.x/requests
- Laravel 13 HTTP client: https://laravel.com/docs/13.x/http-client
- laravel/laravel
config/database.php: https://raw.githubusercontent.com/laravel/laravel/13.x/config/database.php - laravel/laravel
config/app.php: https://raw.githubusercontent.com/laravel/laravel/13.x/config/app.php