Docker Community Forums

Share and learn in the Docker community.

MACVLAN duplicate entries in the router

I use MACVLAN to give my containers their own IP address. Unfortunately, each container gets an additional IP address from the router’s DHCP server in addition to the static IP address I set. The additional IP address contains a random MAC address that changes with every reboot, i. e. some useless entries accumulate in the router over time.
What is going wrong?

Greeting Ulf

are your containers running a dhcp client? Usually a docker container attached to a macvlan network will not get a dhcp lease unless you’ve gone out of your way to configure it to do so. When I run the macvlan driver, I specify a range on the docker network create command that is specifically outside the range that the dhcp server is configured to use as assignable addresses.

Create a macvlan network
When you create a macvlan network, it can either be in bridge mode or 802.1q trunk bridge mode.

In bridge mode, macvlan traffic goes through a physical device on the host.

In 802.1q trunk bridge mode, traffic goes through an 802.1q sub-interface which Docker creates on the fly. This allows you to control routing and filtering at a more granular level.

Bridge mode
To create a macvlan network which bridges with a given physical network interface, use --driver macvlan with the docker network create command. You also need to specify the parent, which is the interface the traffic will physically go through on the Docker host.

$ docker network create -d macvlan
–subnet=172.16.86.0/24
–gateway=172.16.86.1
-o parent=eth0 pub_net
If you need to exclude IP addresses from being used in the macvlan network, such as when a given IP address is already in use, use --aux-addresses:

$ docker network create -d macvlan
–subnet=192.168.32.0/24
–ip-range=192.168.32.128/25
–gateway=192.168.32.254
–aux-address=“my-router=192.168.32.129”
-o parent=eth0 macnet32
802.1q trunk bridge mode
If you specify a parent interface name with a dot included, such as eth0.50, Docker interprets that as a sub-interface of eth0 and creates the sub-interface automatically.

$ docker network create -d macvlan
–subnet=192.168.50.0/24
–gateway=192.168.50.1
-o parent=eth0.50 macvlan50
Use an ipvlan instead of macvlan
In the above example, you are still using a L3 bridge. You can use ipvlan instead, and get an L2 bridge. Specify -o ipvlan_mode=l2.

$ docker network create -d ipvlan
–subnet=192.168.210.0/24
–subnet=192.168.212.0/24
–gateway=192.168.210.254
–gateway=192.168.212.254
-o ipvlan_mode=l2 ipvlan210
Use IPv6
If you have configured the Docker daemon to allow IPv6, you can use dual-stack IPv4/IPv6 macvlan networks.

$ docker network create -d macvlan
–subnet=192.168.216.0/24 --subnet=192.168.218.0/24
–gateway=192.168.216.1 --gateway=192.168.218.1
–subnet=2001:db8:abc8::/64 --gateway=2001:db8:abc8::10
-o parent=eth0.218
-o macvlan_mode=bridge macvlan216

I set up the MACVLAN via ‘Portainer’ (I want to assign more than one IP address)

1 First the configuration:
2 then the network-definition:
3 When creating a new container, I use the network and assign the container an IP address from the pool of the MACVLAN:

Am I doing something wrong??

Lewish is a bot. The response was stolen from the official docker docs: https://docs.docker.com/network/macvlan/#create-a-macvlan-network

It’s a pitty the @moderators don’t care about anything in this forum…

@skyhobbit007 is your docker host a Raspberry Pi?
I encountered a similar issue, could you please check if your scenario matches with what is described in this thread:

Yes …I also use a Raspberry Pi 4.

But I found a workaround: If you give the Raspberry itself a fixed IP-Address, everything works without problems.

Ok, thats good news :slight_smile:
I already tried that by setting a static ipv4 address via /etc/dhcpcd.conf and saw no difference.
How did you do it?

I have the same problem on my Raspberry Pi4.

Is there any news?