balenaOS on RPI 3B+ need to assign docker a macvlan (DHCP) that is visible on local network

I need to create 3 separate docker containers (with alpine) and I need the network interface to be accessible from the local network (same as host, but DHCP and individual interaces on each, not all like when using --net=host) can someone help me accomplish this?

Thanks! :+1:

EDIT:

On my RPI build (Raspbian) I was creating 3 macvlans

ip link add link eth0 name eth0.1 address xx:xx:xx:xx:xx:xx type macvlan
ip link add link eth0 name eth0.2 address xx:xx:xx:xx:xx:xx type macvlan
ip link add link eth0 name eth0.3 address xx:xx:xx:xx:xx:xx type macvlan

But when I created my containers and assiged --net=eth0.0 I get a network not found error.

Hello @edgararroyo

I don’t think that’s how docker’s --net= option works.

I’ve never done this before and I have no idea if it will work. I’m not sure this is supported on Balena.

Docker macvlan docs: https://docs.docker.com/v17.09/engine/userguide/networking/get-started-macvlan/
docker-compose networking docs: https://docs.docker.com/compose/networking/

a docker-compose.yml file like this might work (not tested):

version: "3"
services:
  service1:
    build: ./service1
    networks:
      - network1
  service2:
    build: ./service2
    networks:
      - network2
  service3:
    build: ./service3
    networks:
      - network3
networks:
  network1:
    driver: macvlan
    driver_opts:
      parent: "eth0"
  network2:
    driver: macvlan
    driver_opts:
      parent: "eth0"
  network3:
    driver: macvlan
    driver_opts:
      parent: "eth0"

Thank you for your response. I ended up doing this on Raspbian, but I need a balenaOS solution still.

# Get IPv4 for Gateway, Subnet Mask and IP Addresses
while [ -z “$ip4” ]

do
ip4="$(ip -o -4 addr list eth0 | awk ‘{print $4}’ | cut -d. -f1,2,3)"
done

# Create Docker network
docker network create -d macvlan --subnet="$ip4.0/24" --gateway="$ip4.1" -o parent=eth0 \
-o macvlan_mode=bridge eth0

# Run dockers
docker run -d --name=‘alpine1’ --net=‘eth0’ --ip="$ip4.101" ‘alpine’ tail -f /dev/null
docker run -d --name=‘alpine2’ --net=‘eth0’ --ip="$ip4.102" ‘alpine’ tail -f /dev/null
docker run -d --name=‘alpine3’ --net=‘eth0’ --ip="$ip4.103" ‘alpine’ tail -f /dev/null

Problem now is, if I use this RPI on another network that does not use subnet mask 0/24 and/or gateway .1 and/or ip addresses 101 thru 103, this will not work

Can I create a docker network macvlan that uses DHCP?

Hi,

I have done some quick testing and I do not think the macvlan plugin is supported in balena-engine. I have asked a collegue from the balena-engine team to comment though, as I may be mistaken.

@richbayliss ok, thanks. Also, can you find out if they can add the ipam dhcp driver?

Thanks again.

I don’t think it will be a case of adding them; we deliberately removed the plugin system from moby to reduce on-disk space usage. I am only unsure if this also included macvlan which is what I have asked for clarification of, but I would not expect that it would be desirable to add it back in.

Huh… Ok, thanks.

Hi, I can confirm that macvlan is intentionally removed from balenaEngine https://github.com/balena-os/balena-libnetwork/commit/9e7c869176ffe3131c65506747e361d6ba7ca2de

Is it possible to re-add in a custom build @lucianbuzzo ? I have need of it.

Hi there,

If you wish to roll your own version of balenaOS with a patched balenaEngine, you can find instructions on hacking on balenaEngine here (https://github.com/balena-os/balena-engine/tree/master/hack) and building custom images here (https://www.balena.io/os/docs/custom-build/).

We also offer custom board support plans which may better suit you, you can reach out to our sales folks directly if you are interested (https://www.balena.io/contact-sales).

Thanks. Sorry for not seeing this sooner. I’ll give it a shot. :smiley: