Using, for example, Ubuntu image, I’d like to setup VLANs that are internal to a container. This means my host neither has VLANs of its own nor is aware of the VLANs internal to the container.
I’ve been toying around with network related configs, but most applications of VLAN is not what I need.
FWIW, this is my docker-compose.yml
:
version: '3'
services:
vlan42:
image: vlan-container
command: tail -f /dev/null
networks:
vlan42:
ipv4_address: 192.168.42.4
environment:
VLAN: 42
networks:
vlan42:
driver: macvlan
ipam:
config:
- subnet: 192.168.42.0/24
It’s setting up the right IP address to an interface, but it’s not tagging with a VLAN:
root@199ecda0d9a6:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
98: eth0@if97: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:c0:a8:2a:04 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 192.168.42.4/24 brd 192.168.42.255 scope global eth0
valid_lft forever preferred_lft forever
Perhaps I shouldn’t try to get this accomplished through docker-compose
. If so, please feel free to suggest a suitable alternative approach. I’m hoping this is possible without having to resort to a shell script containing commands like this:
ip link add link eth0 name vlan42 type vlan id 42