The end goal is to have a macvlan interface set up within a Podman container. I have the following Dockerfile
FROM docker.io/library/debian:bookworm-slim
RUN apt-get --yes install systemd
RUN systemctl set-default multi-user.target
CMD ["/lib/systemd/systemd"]
If I then run this in privileged mode (detached) and attach a shell to the running container (as root), I can set up a macvlan interface called macvlan1 on the default tap interface using iproute2:
# apt install iproute2
# ip link add macvlan1 link tap0 type macvlan mode bridge
However, I want to avoid this, and I think it should be possible using systemd-networkd, but I'm not having much luck. I've tried the following .network and .netdev files (which I have tested to work on my host machine):
### 99-test.network
[Match]
Name=tap0
[Network]
MACVLAN=macvlan1
### 99-test.netdev
[Match]
# Empty
[NetDev]
Name=macvlan1
Kind=macvlan
[MACVLAN]
Mode=bridge
I update my Dockerfile like so:
FROM docker.io/library/debian:bookworm-slim
COPY 99-test.network /lib/systemd/network
COPY 99-test.netdev /lib/systemd/network
RUN apt-get --yes install systemd
RUN systemctl set-default multi-user.target
RUN systemctl enable systemd-networkd
CMD ["/lib/systemd/systemd"]
But when I start up the container, I see no macvlan interface created. If I look at the output of systemctl status systemd-networkd there are no logs or error messages suggesting that it's attempted to read the .network and .netdev files. The only clue I have is that when I run networkctl on my host machine, it shows the physical interfaces as unmanaged in the SETUP column whereas in the container, it shows all interfaces as pending (including for a manually-created macvlan interface).
Is what I'm trying to do possible with systemd in Podman? If not, why not?
You can set up a
--driver macvlannetwork (configurable with--options) outside the container as apodman network. Then "plug it in" to thepodman containerwith--network <name>.To avoid manual setup steps, see also Podman Quadlet usage with
[Container]Network=<name>.networkand[Network]Driver=macvlanfor augmented systemd unit files. (Note that Quadlet*.networkunits are completely separate fromsystemd-networkd*.networkfiles.)This way Podman resources and unit files are set up on the host, keeping the container light-weight. There is no need to install
systemdin the container, which would then become "too heavy".Also consider running the container and macvlan network in rootless mode, either as yourself or as systemd services from a separate unprivileged
loginctl enable-lingeruser.