Skip to main content
Containers typically use network namespaces for isolation, but some legacy applications require direct attachment to the physical LAN. Docker’s MACVLAN driver assigns each container its own MAC address on a virtual interface, making the container appear as a standalone host on your network. This guide covers how to create a MACVLAN network, the available modes, and a comparison of Docker’s built-in network drivers.

Why Use MACVLAN?

  • Direct Layer 2 connectivity with your physical network
  • Unique MAC addresses for each container
  • Support for legacy applications requiring their own IP on the LAN
Before you begin, ensure the parent interface (eth0 in these examples) is active and not part of another bridge. You may need to bring it up with ip link set eth0 up.

1. Creating a MACVLAN Network

Use the macvlan driver when creating a Docker network:
Parameters:
  • -d macvlan
    Selects the MACVLAN driver.
  • --subnet / --gateway
    Defines the IP range and default gateway on the physical LAN.
  • -o parent=eth0
    Binds Docker’s MACVLAN to the host interface eth0.
  • my_macvlan_net
    Your custom network name.

2. MACVLAN Modes

MACVLAN supports two primary modes for segmenting and isolating traffic:
Your physical switch must support 802.1Q tagging, and the parent interface must be configured as a trunk port to carry multiple VLANs.

3. Summary of Docker Network Drivers

Here’s a quick reference table comparing Docker’s built-in network drivers:

4. Next Steps

Once your MACVLAN network is created, you can launch containers on it:
Each container will receive an IP from your defined subnet and appear as a physical host on the LAN. That concludes this lesson on Docker MACVLAN networks. Advanced multi-VLAN and trunking scenarios will be covered in a future guide.

Watch Video