Tutorials · DevOps & Containers
How to Put Containers on Your VLANs With Docker macvlan
Some edge applications need their own IP on a real VLAN, for example a camera analytics app on the CCTV VLAN. Use a macvlan network on a tagged trunk to the edge server.
Before you start
- A NavEdge edge server connected to a switch trunk port
- The VLAN IDs and free IP ranges
- Root or sudo access
Step by step
Configure the switch port
Make the edge server's switch port a trunk that carries the VLANs the containers need, for example 30 (CCTV) and 40 (IoT).
Create the macvlan network
Docker creates the VLAN sub-interface (eth0.30) for you. Reserve an IP range that your DHCP server does not hand out.
docker network create -d macvlan \ --subnet 10.1.30.0/24 --gateway 10.1.30.1 \ --ip-range 10.1.30.224/28 \ -o parent=eth0.30 cctv30
Attach a container
Give the container a fixed address in the reserved range.
docker run -d --name analytics --restart unless-stopped \ --network cctv30 --ip 10.1.30.230 \ ghcr.io/example/video-analytics:1.8.0
Allow host-to-container traffic
By design the host cannot talk to its own macvlan containers. Add a small macvlan shim interface on the host if it needs to.
ip link add cctv-shim link eth0.30 type macvlan mode bridge ip addr add 10.1.30.239/32 dev cctv-shim ip link set cctv-shim up ip route add 10.1.30.224/28 dev cctv-shim
Firewall the VLAN
The container is now a normal host on VLAN 30, so the gateway's inter-VLAN rules apply to it like any camera or NVR.
Document
Add the container IPs to your IP plan so nobody assigns them twice.
Commands are generic, industry-standard examples. Exact syntax and menu names vary by model and firmware; check your device's manual on the Documentation page.
Pro tips
- Some switches limit the number of MAC addresses per port (port security): raise the limit for the edge server's trunk.
- Use ipvlan instead if the network does not accept several MAC addresses on one port.
FAQ
Frequently asked questions
Bridge or macvlan?
Use the default bridge network with published ports for most apps. Use macvlan only when an app must appear as its own device on a VLAN.
Keep learning
Related guides
Configure VLANs on a managed switch
Read more →Port security and MAC limiting
Read more →IP addressing and subnet planning
Read more →How to Use SSH Keys Instead of Passwords for Network Devices and Servers
Passwords can be guessed, phished and reused. Create an SSH key pair, install the public key on gateways, edge servers and Linux hosts, then turn password logins off.
Read more →How to Reach Remote Sites Safely With an SSH Jump Host
Do not expose SSH on every device. Put one hardened jump host (bastion) in front of the management network and reach everything else through it.
Read more →How to Open a Device Web Page Through an SSH Tunnel
Reach the web interface of a switch, NVR or container on a remote site without opening a firewall port: forward it through SSH.
Read more →Stuck on a step?
Ask Navijin technical support or an authorised partner for help with your configuration.