Multipe macvlan Ips for nested docker containers

Hi,

i’m not sure how i should fix this. I used to have multiple macvlan (tagged) networks. On each network i had multiple containers running, having different ips.

from my old docker-compose:

version: "3"
services:
  a:
    ...
    networks:
      vpnvlan:
        ipv4_address: 192.168.20.150
  b:
    ...
    networks:
      vpnvlan:
        ipv4_address: 192.168.20.160

networks:
  vpnvlan:
    driver: macvlan
    driver_opts:
      parent: eth0.1020
    ipam:
      config:
        - subnet: 192.168.20.0/24
          gateway: 192.168.20.1

Since i wanted to try lxd, i got stuck.

  1. It seems that i can create macvlan IF and attach it to an lxc container… it even gets the ip.

    • but then how do i pass the proper parent to docker, such that it can take or create the proper
      network and then assign correctly the ips?
      using it as above does not work
  2. i had an idea to create multiple macvlan ifs as profile and attach it to an lxc container and the assign it 1 by 1 to docker containers, but somehow this feels a bit klunky in comparison

should i then use this profile (which works for dhcp) and create multiple devices?

config: {}
description: ""
devices:
  eth0:
    name: eth0
    nictype: macvlan
    parent: eno1
    type: nic
    vlan: "1020"
name: macvlan20
used_by:
- /1.0/instances/ubuntu-container
  1. How do i set a static IP of a macvlan IF for the lxc container, using ip command inside the container did not work unfortunately, although dhcp works perfectly

I think i solved the Static ip problem of a lxc container:
“/etc/netplan/50-cloud-init.yaml”

ethernets:
eth0:
dhcp4: no
dhcp6: no
addresses:
- 192.168.20.111/24
gateway4: 192.168.20.1
nameservers:
addresses:
- 192.168.20.1
- 8.8.8.8

and then:
netplan --debug apply

works like a charm (found here Lxd + Netplan + Static IP's in same subnet HOW-TO - #7 by sdurnov)

I think a fresh day solved my multiday problem.

i had a wrong docker network parent in lxd world.
I had before:

  vpnvlan:
    driver: macvlan
    driver_opts:
      parent: **eth0.1020**

which worked in plain non nested docker

now i changed it to eth0 without the vlan tag:

  vpnvlan:
    driver: macvlan
    driver_opts:
      parent: **eth0**

and it works like a charm :slight_smile: IPs are also allocated correctly

so to reitarate.

my macvlan profile

config: {}
description: ""
devices:
  eth0:
    name: eth0
    nictype: macvlan
    parent: eno1
    type: nic
    vlan: "1020"
name: macvlan20
used_by:

and docker-compose:

version: "3"
services:
  a:
    ...
    networks:
      vpnvlan:
        ipv4_address: 192.168.20.150
  b:
    ...
    networks:
      vpnvlan:
        ipv4_address: 192.168.20.160

networks:
  vpnvlan:
    driver: macvlan
    driver_opts:
      parent: eth0
    ipam:
      config:
        - subnet: 192.168.20.0/24
          gateway: 192.168.20.1
1 Like