Docker Community Forums

Share and learn in the Docker community.

Need help - docker macvlan static ip - yet a dhcp request

Hi, first of all, I hope this is the right place / category for such a question.

I’m trying to run 2 docker containers on my Raspberry Pi with each having it’s own static ip address.
So far, I got it working using the macvlan network driver.
But there’s this strange behaviour: Whenever I start a container, my router (Fritz!Box 7590) is reporting a new network device and assigns a new ip to it. The container is reacheable on it’s static ip and the automatically assigned ip is just unused and fills up the DHCP leases. Every (re-)start, a new unused ip.

How can I stop these unnecessary DHCP requests?
I’m just getting warm with docker, any help is appreciated!

My specific network and container configuration (my router’s home network is on 192.168.2.x):

docker network create -d macvlan --subnet=192.168.2.0/24 --gateway=192.168.2.1 -o parent=eth0 home_network

docker run -d --name "diyHue" -v '/mnt/hue-emulator/export/':'/opt/hue-emulator/export/':'rw' -e MAC='02:42:AC:F8:1B:B8' -e IP='192.168.2.241' -p 80:80/tcp -p 443:443/tcp -p 1900:1900/udp -p 2100:2100/udp -p 1982:1982/udp --ip 192.168.2.241 --mac-address 02:42:AC:F8:1B:B8 --network home_network --restart always diyhue/core:latest

docker run --init -d --name="home-assistant" -v /home/pi/homeassistant:/config -v /etc/localtime:/etc/localtime:ro --network home_network --ip 192.168.2.242 --mac-address 02:42:AC:11:CE:10 --restart always homeassistant/raspberrypi3-homeassistant

Hi, I experienced this exact same problem and never found a solution for it.
Every time I add another container to my macvlan or reboot one of the existing, my router receives another DHCP lease with a random MAC address and the the hostname of my docker host.
This makes my docker host unreachable by its name, since DNS now has several entries for all these random MAC addresses.

I found out, that it seems to be Raspberry Pi related. Tested this on a Pi 2 und Pi 4 with different kernels (4.19.118 to 5.4.83) of Raspbian / RaspiOS and HypriotOS aswell. Allways the same behaviour.
But when I run the same configuration on a PC hardware with Debian 4.19.118 as a docker host, this issue does NOT occur.

Any ideas for further troubleshooting are appreciated :slight_smile:

@dreiekk did you ever solve this issue or found a workaround?

Thanks!
Kind regards
Thomas

I had it at --net=home_network and then it worked for me (in stead of --network take --net.

first: docker network create -d macvlan --subnet=192.168.2.0/24 --gateway=192.168.2.254 --ip-range=192.168.2.100/28 -o parent=eth0 vlan

second: docker run -d --name=iot -p 8080:8080 -p 4443:4443 --net=vlan -v /home/ubuntu/data/iot:/home/node/.mozilla-iot -e TZ=‘Europe/Amsterdam’ mozillaiot/gateway:arm

I then set my router to never give out ip’s above 192.168.2.100 (vlan does that now) do it will not conflict.

You copied the answer someone else wrote to the OP’s question at superuser-dot-com.
But I do not understand how this is supposed to help. The router assignes IP addresses from its pool, this has nothing to do with the ip range I configured for the docker macvlan network.