macvlan Networks on Docker

1 minute read

If your application or container needs to be directly on the network, or it needs to use ports that are already in use by the host or other containers, such as 80/443 or 53, then you can work around this using the macvlan network driver.


What is not obvious from the examples on the Docker docs and elsewhere the web, is that the values you use when creating the network can match your existing LAN. They don’t have to, since you may want a different subnet, but they can do if you want docker containers to have their own interface and MAC address on the existing network.

Assuming your home network is with a router at, this command will create a Docker network called “macvlan_net” which you can then attach containers to:

docker network create -d macvlan --subnet= --gateway= -o parent=eno1 macvlan_net

-o parent=eno1 must match the interface which is connected to to the LAN.

You only need to create it once, then use it as many times as you need to for different containers.

I have used this for pihole, so that it appears on the network as ip (excerpt from compose file):

    external: true

NOTE: for subsequent containers on the same network, you don’t need to create it, you just reference it in compose file, with a DIFFERENT ipv4_address.