7.2.5.5 Macvlan Advanced Scenarios
A focused guide to Macvlan Advanced Scenarios, connecting core concepts with practical Docker and container operations.
Macvlan advanced scenarios cover less common but valid use cases for the macvlan driver beyond basic single-container deployment, including running multiple macvlan networks against different physical interfaces and combining macvlan with VLAN tagging for more complex network segmentation.
Running Multiple Macvlan Networks on Different Interfaces
A host with multiple physical network interfaces can have a separate macvlan network configured against each, allowing different containers to appear on different physical network segments.
docker network create -d macvlan --subnet=192.168.1.0/24 -o parent=eth0 net-a
docker network create -d macvlan --subnet=192.168.2.0/24 -o parent=eth1 net-b
Containers on net-a appear on the network connected to eth0; containers on net-b appear on the entirely separate network connected to eth1.
Combining Macvlan With VLAN Sub-Interfaces
For environments using VLAN segmentation, macvlan networks can each target a specific VLAN sub-interface, placing different sets of containers onto different VLANs from a single physical interface.
docker network create -d macvlan --subnet=192.168.10.0/24 -o parent=eth0.10 vlan10-net
docker network create -d macvlan --subnet=192.168.20.0/24 -o parent=eth0.20 vlan20-net
Macvlan in Bridge Mode for Inter-Container Communication
Macvlan's bridge mode (the typical mode) allows containers on the same macvlan network to communicate with each other directly, in addition to their direct physical network presence.
docker run -d --network net-a --ip=192.168.1.50 container-a:1.0
docker run -d --network net-a --ip=192.168.1.51 container-b:1.0
docker exec container-a ping 192.168.1.51
Why Understanding These Advanced Scenarios Matters
Recognizing that macvlan supports more sophisticated configurations — multiple interfaces, VLAN integration — beyond the simplest single-network setup helps in designing more complex network segmentation strategies for the specific, less common deployments that genuinely require this driver's particular capabilities.