Networking using a macvlan network (original) (raw)
This series of tutorials deals with networking standalone containers which connect to macvlan
networks. In this type of network, the Docker host accepts requests for multiple MAC addresses at its IP address, and routes those requests to the appropriate container. For other networking topics, see theoverview.
The goal of these tutorials is to set up a bridged macvlan
network and attach a container to it, then set up an 802.1Q trunked macvlan
network and attach a container to it.
- Most cloud providers block
macvlan
networking. You may need physical access to your networking equipment. - The
macvlan
networking driver only works on Linux hosts, and is not supported on Docker Desktop or Docker Engine on Windows. - You need at least version 3.9 of the Linux kernel, and version 4.0 or higher is recommended.
- The examples assume your ethernet interface is
eth0
. If your device has a different name, use that instead. - The
macvlan
driver is not supported in rootless mode.
In the simple bridge example, your traffic flows through eth0
and Docker routes traffic to your container using its MAC address. To network devices on your network, your container appears to be physically attached to the network.
- Create a
macvlan
network calledmy-macvlan-net
. Modify thesubnet
,gateway
, andparent
values to values that make sense in your environment.
You can usedocker network ls
anddocker network inspect my-macvlan-net
commands to verify that the network exists and is amacvlan
network. - Start an
alpine
container and attach it to themy-macvlan-net
network. The-dit
flags start the container in the background but allow you to attach to it. The--rm
flag means the container is removed when it is stopped. - Inspect the
my-macvlan-alpine
container and notice theMacAddress
key within theNetworks
key: - Check out how the container sees its own network interfaces by running a couple of
docker exec
commands. - Stop the container (Docker removes it because of the
--rm
flag), and remove the network.
In the 802.1Q trunked bridge example, your traffic flows through a sub-interface of eth0
(called eth0.10
) and Docker routes traffic to your container using its MAC address. To network devices on your network, your container appears to be physically attached to the network.
- Create a
macvlan
network calledmy-8021q-macvlan-net
. Modify thesubnet
,gateway
, andparent
values to values that make sense in your environment.
You can usedocker network ls
anddocker network inspect my-8021q-macvlan-net
commands to verify that the network exists, is amacvlan
network, and has parenteth0.10
. You can useip addr show
on the Docker host to verify that the interfaceeth0.10
exists and has a separate IP address - Start an
alpine
container and attach it to themy-8021q-macvlan-net
network. The-dit
flags start the container in the background but allow you to attach to it. The--rm
flag means the container is removed when it is stopped. - Inspect the
my-second-macvlan-alpine
container and notice theMacAddress
key within theNetworks
key: - Check out how the container sees its own network interfaces by running a couple of
docker exec
commands. - Stop the container (Docker removes it because of the
--rm
flag), and remove the network.