Skip to main content

Creating a Macvlan in Docker

Creating a Macvlan Network for Docker

This guide provides step-by-step instructions for creating a Macvlan network in Docker. A Macvlan network allows Docker containers to have their own MAC addresses, making them appear as physical devices on your network.

Steps to Create a Macvlan Network

Step 1: Determine the Subnet and Gateway

Before creating a Macvlan network, determine the subnet and gateway of your network. You will need this information to configure the Macvlan network correctly.

Step 2: Create the Macvlan Network

Open your terminal and use the following command to create a Macvlan network. Replace subnet, gateway, and parent with your network's details:

docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=eth0 nomad

Find which interface: ifconfig -a

In this example:

  • --subnet specifies the subnet for the Macvlan network.
  • --gateway specifies the gateway for the Macvlan network.
  • -o parent specifies the parent interface to which the Macvlan network is attached (e.g., eth0).
  • my_macvlan_network is the name of the Macvlan network you are creating.

Step 3: Verify the Macvlan Network

After creating the Macvlan network, verify its creation by listing all Docker networks:

docker network ls