I ran across the above issue today and found this blog post that helped me out. Essentially you create a new network device on your host, assign it an IP, bring it up, and modify the routing tables so that traffic to the macvlan subnet go via that IP.
My setup is slightly different because unlike the author I don’t randomly assign IPs in my macvlan network. As I alluded to in an earlier post I create a macvlan network and then assign an IP to each container in that network. I’ll repeat the same below just to recap.
Create the macvlan network:
docker network create -d macvlan \
-o parent=eth0 \
Now create a container and assign it an IP manually:
docker create --name "$NAME" \
-P --network="$NETWORK" --ip=$IP \
In my specific case the instructions from the blog post I linked to will be as below:
# create the interface; I call it macvlan0 instead of mynet-shim
ip link add macvlan0 link eth0 type macvlan mode bridge
# assign it an IP address; note the /32 subnet
ip addr add 192.168.1.223/32 dev macvlan0
# bring it up
ip link set macvlan0 up
# tell my host to route to the container IP via this interface
# 192.168.17.6 is the $IP assigned to the container above
ip route add 192.168.1.20/32 dev macvlan0
It is a bit of a chore I know, my decision to assign IPs manually means I’ll have to repeat that last line for each new container in this macvlan network. But that’s fine by me.
Of course the above steps have to be redone upon a reboot. So I added them to my
/etc/network/interfaces file to automate it:
# macvlan for docker
iface macvlan0 inet manual
pre-up ip link add macvlan0 link eth0 type macvlan mode bridge
pre-up ip addr add 192.168.1.233/32 dev macvlan0
up ip link set macvlan0 up
post-up ip route add 192.168.1.20/32 dev macvlan0
Same commands as earlier, just that I create a “manual” interface and specified these commands via bunch of “pre-up” and “up” and “post-up” commands.
Hope this helps anyone else in the same situation!