User Tools

Site Tools


docker:network:macvlan

MACVLAN

Dual stack
docker network create -d macvlan \
  --ipv6 \
  --subnet=192.168.222.0/24 \
  --subnet=2001:db8:1d:2ec::/64 \
  --gateway=192.168.222.1 \
  --gateway=2001:db8:1d:2ec::1 \
  -o parent=enp5s0f3.100 \
  vlan100
IPV4 only
docker network create -d macvlan \
  --subnet=192.168.222.0/24 \
  --gateway=192.168.222.1 \
  -o parent=enp5s0f3.100 \
  vlan100-ipv4
IPV6 only
docker network create -d macvlan \
  --ipv6 \
  --subnet=2001:db8:1d:2ec::/64 \
  --gateway=2001:db8:1d:2ec::1 \
  -o parent=enp5s0f3.100 \
  vlan100-ipv6
To test it
docker run --rm -it --name alpine --network vlan100 alpine ping ipv6.google.com
docker run --rm -it --name alpine --network vlan100 alpine ping 8.8.8.8
docker run --rm -it --name alpine --network vlan100-ipv4 alpine ping 8.8.8.8
docker run --rm -it --name alpine --network vlan100-ipv6 alpine sh ping ipv6.google.com
docker run --rm -it --name alpine --network vlan100-ipv4 --network vlan100-ipv6 alpine ping 8.8.8.8
docker run --rm -it --name alpine --network vlan100-ipv4 --network vlan100-ipv6 alpine ping ipv6.google.com
docker-compose format
services:
  alpine:
    image: alpine
    stdin_open: true
    tty: true
    cap_add:
      - NET_ADMIN
    command: ["sh", "-c", "ip route replace default via 192.168.222.1 dev eth1 && sh"]
    networks:
      vlan100-ipv4:
        ipv4_address: 192.168.222.200
      vlan100-ipv6:
        ipv6_address: 2001:db8:1d:2ec::200
 
networks:
  vlan100-ipv4:
    external: true
 
  vlan100-ipv6:
    external: true
IP assignment doesn't work with docker run
IP assignment doesn't work with docker run
root@ucpe2:~/test# docker run -it --rm \
  --name alpine \
  --cap-add=NET_ADMIN \
  --network vlan100-ipv4 --ip 192.168.222.200 \
  --network vlan100-ipv6 --ip6 2001:db8:1d:2ec::200 \
  alpine \
  sh -c "ip route replace default via 192.168.222.1 dev eth1 && sh"
docker: Error response from daemon: invalid config for network vlan100-ipv4: invalid endpoint settings:
user specified IP address is supported only when connecting to networks with user configured subnets
docker/network/macvlan.txt · Last modified: by jonathan