MACVLAN creates multiple virtual network interfaces with different MAC addresses. This way if your system has multiple IP addresses with MAC addresses then we can create multiple virtual network interfaces each having their own IP address and MAC address.
MACVLAN doesn’t need to learn(identify) mac addresses of the systems within the network to distribute traffic as it knows every mac address, this makes it fast and easy to setup than bridge type networking.
Problems with docker containers port binding:
Advantages of MACVLAN:
Creating MACVLAN network:
Example:
Host IP: 188.40.102.103
Host subnet: 188.40.76.0
Host Mask: 26
Host gateway: 188.40.76.1
Host ethernet interface: eth0
docker network create -d macvlan -o macvlan_mode=bridge --subnet=188.40.76.0/26 --gateway=188.40.76.1 -o parent=eth0 macvlan_bridge
Above command creates network named ‘macvlan_bridge’
Running a container using ‘macvlan_bridge’ network:
Example:
Host contains multiple publicly accessible IP addresses with MAC addresses.
Host additional IP/MAC: 88.99.102.115/00:50:56:00:60:42
docker run --name cont1 --net=macvlan_bridge --ip=88.99.102.115 --mac-address 00:50:56:00:60:42 -itd nginx
Above command runs nginx container with ip ‘88.99.102.115’ attached to this container, you can verify by hitting ‘88.99.102.115’ where you will be welcomed with nginx page.
This way overall network setup will become clear and easy to handle.