What does the host network driver do, and what do you observe when nginx runs with --network host?
The container shares the host's network stack directly: no own IP, no veth, no NAT and no port mapping. nginx itself binds port 80 on the host, while storage, processes and users stay isolated.
With docker container run -d --network host --name hostnginx nginx, the container skips its own network namespace. The application behaves network-wise as if it were started on the host:
http://localhost(port 80) shows the nginx page without any-p; publishing ports has no effect in host mode.ip addr showshows no newvethinterface, only thedocker0bridge that always exists.sudo ss -ltnp 'sport = :80'shows the nginx process itself listening on0.0.0.0:80(for a bridge container with-pyou'd see Docker's port-forwarding instead).- The port must be free: the lab first stops the host's own Apache (
sudo systemctl disable --now apache2), otherwise nginx could not bind 80.
Trade-off: host mode is faster (no NAT, no bridge) and handy for tools that must see the host's real interfaces. But it gives up network isolation: the container can bind any host port and reach services listening only on the host's localhost. The other isolation (filesystem, PID and user namespaces) still applies.
* The container shares the host's network stack; other namespaces stay separate. *
Go deeper:
Docker Docs: Host network driver โ behaviour, limits and why
-pis ignored.