DEV Community

Wycliffe A. Onyango
Wycliffe A. Onyango

Posted on

100 Days of DevOps: Day 42

Setting Up a Docker Macvlan Network

Docker's macvlan network driver allows containers to appear as physical devices on your network. This is incredibly useful for applications that need to be directly accessible from the physical network without port mapping, or for creating a network environment where each container has its own unique MAC address and IP. This article will walk you through the process of creating and verifying a Docker network using the macvlan driver.

Step 1: Create the Macvlan Network

To create a macvlan network, you'll use the docker network create command. This command is highly flexible, letting you specify the driver, subnet, and IP range. In this example, we'll create a network named blog with a subnet and IP range of 172.28.0.0/24.

Here's the command used:

[steve@stapp02 ~]$ docker network create -d macvlan --subnet=172.28.0.0/24 --ip-range=172.28.0.0/24 blog
Enter fullscreen mode Exit fullscreen mode

The output confirms the network's creation by providing its unique ID:

5e9cef370a8a3017dfff2c48b4e31391c9c79f2cf0e4d48648dce92481df6128
Enter fullscreen mode Exit fullscreen mode

Step 2: Verify the Network's Existence

After creation, it's good practice to verify that the network has been set up correctly. You can list all existing Docker networks using the docker network ls command.

[steve@stapp02 ~]$ docker network ls
Enter fullscreen mode Exit fullscreen mode

This command provides a clean, table-formatted output of all networks. You should see blog listed with macvlan under the DRIVER column, confirming its successful creation and driver type.

NETWORK ID      NAME      DRIVER    SCOPE
5e9cef370a8a    blog      macvlan   local
ecc55a5f1887    bridge    bridge    local
98aaf841e624    host      host      local
4759c790bb09    none      null      local
Enter fullscreen mode Exit fullscreen mode

Step 3: Inspect Network Details

For a detailed view of the network's configuration, use the docker network inspect command. This command returns a JSON object containing comprehensive information about the network, including its driver, IPAM (IP Address Management) settings, and any connected containers.

Here's the command to inspect our newly created network:

[steve@stapp02 ~]$ docker network inspect blog
Enter fullscreen mode Exit fullscreen mode

The output, shown below, provides a full overview. We can confirm that the Driver is set to macvlan and the IPAM section correctly shows our specified Subnet and IPRange.

[
    {
        "Name": "blog",
        "Id": "5e9cef370a8a3017dfff2c48b4e31391c9c79f2cf0e4d48648dce92481df6128",
        "Created": "2025-09-14T19:11:22.695106941Z",
        "Scope": "local",
        "Driver": "macvlan",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.28.0.0/24",
                    "IPRange": "172.28.0.0/24"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)