Networking: host, none, and MacVLAN/IPVLAN
Bridge is the default. These four modes change how much private network a container gets, from all of it to none of it.
key idea / Docker itselfcontainer / good pathhost / watch outproblem / blockedneutral
Four modes at a glance
| Mode | Use it when | Cost |
|---|---|---|
bridge | almost always | one NAT hop |
host | you need peak network performance | no isolation, shared ports |
none | the job must never touch a network | no connectivity at all |
macvlan | the container must appear as its own device | needs LAN cooperation |
host: no isolation on purpose
macvlan and ipvlan
| macvlan | ipvlan | |
|---|---|---|
| MAC address | a new MAC per container | shares the parent's MAC |
| Switch needs | to allow several MACs per port | nothing special |
| Wi-Fi interfaces | often dropped | usually works |
| Use it when | a legacy app needs its own LAN identity | the network limits MACs per port |
Try it yourself
On Docker Desktop, --network host shares the Linux VM’s network, not the Mac’s interfaces.
-
Step 1 · none has only loopback
$ docker run --rm --network none alpine:3.20 ping -c 1 1.1.1.1 ping: bad address '1.1.1.1' $ docker run --rm --network none alpine:3.20 cat /etc/hosts 127.0.0.1 localhost -
Step 2 · host has no separate container address
There is no
eth0in a private namespace. A published-pis unnecessary because the process binds the host stack directly.$ docker run --rm --network host alpine:3.20 cat /etc/hosts # this file is the VM or host hosts file, not a private one -
Step 3 · macvlan asks for a parent interface
Replace
eth0with a real interface on a Linux host. This fails on a laptop Wi-Fi interface that drops extra MAC addresses, which is the point of the check.$ docker network create -d macvlan \ --subnet=192.168.1.0/24 \ --gateway=192.168.1.1 \ -o parent=eth0 lan $ docker network inspect lan --format '{{.Driver}} {{.Options.parent}}' macvlan eth0
Recap
hostshares the host network namespace: fast, but no isolation and shared ports.noneleaves only loopback.macvlangives each container its own MAC and LAN IP;ipvlanshares the parent MAC.- On Docker Desktop, host mode shares the Linux VM network, not your Mac's.
Quick check
Why does a second container with
--network host fail to start nginx on port 80?Show answer
Both containers are in the host namespace, so they share one port table. The first nginx already owns :80.