Host Network
Host network is a Docker network mode where a container shares the host's network stack directly, using the host's IP addresses and ports with no NAT. It is fast but removes network isolation.
What changes with --network host
In the default bridge mode, a container has its own IP and ports and relies on NAT and -p mappings. In host mode there is no separate network namespace, so a process listening on port 8080 in the container listens on port 8080 on the host. Port mappings with -p are ignored.
docker run -d --network host nginx:1.27ss -tulpn | grep :80 # nginx listens directly on the hostWhen it is reasonable
- Monitoring agents such as node exporters that must see host interfaces.
- Latency-sensitive workloads where NAT overhead is measured to matter.
- Network tools that manage host interfaces.
When to avoid it
- Normal application services, because of port collisions and loss of isolation.
- Multi-tenant hosts and anything handling untrusted input.
- Cases where
-pplus a bridge already works.
Platform note
Host mode is native on Linux. On Docker Desktop for Mac and Windows, containers run inside a VM, so "host" means the VM, not your laptop. Recent Docker Desktop versions offer opt-in host networking support, so check current Docker documentation before relying on it.
SecurityA host-mode container can bind any host port and reach services bound to localhost on the host. Treat it like running the process directly on the host.
Frequently Asked Questions
What changes when a container uses host networking?
It skips the virtual bridge, NAT, and port mapping and uses the host network stack directly. A service on port 8080 inside the container is reachable on host port 8080, which removes NAT overhead and isolation.
Why avoid host networking for typical apps?
Containers can collide on ports, a compromised process gets direct access to host interfaces and localhost services, and behavior differs on Docker Desktop. Bridge networking with published ports is safer.
Does -p work with host networking?
No. Port publishing is ignored because the container is already on the host network.