And everything is fine… BUT if I want to run this on a network that uses a different subnet mask and/or gateway and/or IP addresses 101 thru 103 being used, it will not work. Is there a way for me to create the macvlan network using DHCP and avoid having to get the IP and assume gateway is .1 and subnet mask is 0/24?
The --ip option is not mandatory so your container can get its IP address dynamically, but it will not be from DHCP. I don’t think you could do that. As far as I know, Docker just assigns a new IP address from the configured subnet. If you have existing IP addresses in the subnet, Docker can assign those existing IPs to containers. If you want to avoid that, you can use the --aux-address option or --ip-range to use a subset of the available IP addresses in the configured subnet or as the documentation mentions, use a dedicated subnet just for containers on macvlan. The gateway is optional too, but you need to define at least the subnet.
If you have a server, that is not likely to move frequently to different subnets. If you have a laptop, that is not for long-running containers and you can always use a script to regenerate your Docker networks and and recreate your containers without manually modifying anything except the subnet.
If you setup the macvlan network without subnet, docker will automatically assign one to it. As we are going to obtain an ip from DHCP, we actually don’t care what subnet it is.
Since docker assigns the container a non exisiting subnet, the container will have no internet access initially. You will need to make sure that your container has the dhcp client.
Then we want to flush the current assigned ip and obtain one from DHCP server via eth0
It could be done by ip addr flush dev eth0 && dhclient eth0 before running the entrypoint of your image.