Sub topic 10
The host and none drivers
Two of Docker's built-in drivers sit at opposite ends of the isolation spectrum. The host driver removes network isolation. The none driver removes networking entirely. This chapter assumes you know what a network namespace is and how the default bridge and published ports work, from the earlier chapters.
The host driver
With --network host, the container does not get its own network namespace. It shares the host's network stack: the same interfaces, IP addresses, routing table, and port space.
docker run -d --name web-host --network host nginx:alpine
curl http://localhost:80nginx listens on port 80 inside the container, and that port is now open on the host directly. There is no virtual interface pair, no bridge, and no NAT. Packets go straight through the host's stack.
Effects of host networking
- Published ports are ignored.
-p 8080:80has no meaning here, because the container already uses the host's ports. Docker prints a warning if you try. - Port conflicts are your problem. If the host already uses port 80, the container's process fails to bind.
- Less overhead. Skipping NAT and the veth pair helps with very high packet rates or when a service needs many ports.
- No isolation. The container can see all host interfaces and can bind to any port. A compromised process has more network reach.
- No name-based discovery. A host-mode container is not on a user-defined network, so it cannot resolve other containers by name through Docker's DNS.
When to use it
Host mode suits performance-sensitive network services, tools that must see host interfaces (for example monitoring agents), and services that open large or unpredictable port ranges. For ordinary web applications, a user-defined bridge with published ports is the safer default.
The none driver
With --network none, the container gets its own network namespace with only the loopback interface (lo). It has no external connectivity and no route to other containers.
docker run --rm --network none busybox ip addr
docker run --rm --network none busybox ping -c 1 -W 2 8.8.8.8The first command lists only lo with 127.0.0.1. The second fails, because there is no route out.
When to use it
- Batch jobs that process local data and must not reach the network.
- Running untrusted code with a smaller attack surface.
- Containers where you attach custom networking yourself, for example by moving an interface into the namespace with external tooling.
Processes in the container can still talk to each other over 127.0.0.1. Volumes still work, so data can move in and out through mounted paths.
Comparing the drivers
| Property | bridge (user-defined) | host | none |
|---|---|---|---|
| Own network namespace | Yes | No | Yes |
| Interfaces in container | `eth0` plus `lo` | All host interfaces | `lo` only |
| Needs `-p` to be reachable | Yes | No | Not reachable |
| Docker DNS by name | Yes | No | No |
| Outbound access | Yes, via NAT | Yes, directly | No |
Common errors
- "Address already in use" in a host-mode container. Another process on the host holds the port. Find it with
ss -ltnp. - Published port not working with
--network host. The-pflag is ignored. Connect to the application's own port. - Container with
nonecannot install packages or call APIs. This is expected. Use a bridge network for build or setup steps.
Exercise
You run docker run -d --network host -p 8080:80 nginx:alpine on a Linux host where nothing else uses port 80. On which host port is nginx reachable, and why?
Show answer
On port 80. In host mode the container shares the host's network stack, so nginx binds to port 80 directly. The -p 8080:80 mapping is ignored, so port 8080 is not opened.
Exercise
A data-processing container must read files from a mounted volume and must never make network calls. Which network setting fits, and can it still read the volume?
Show answer
Use --network none. The container has only a loopback interface and no external route. Volumes are not part of networking, so it can still read the mounted files.