'Multi-VRF inetrfaces to a single docker

I am facing the same prolem, I wanted this for the sake of associating multiple physical interface son IOS-xr rouuters to a single container. Issue here is the the cisco router with ios xr has got the various vrf . interfaces are associated to global as well as other vrf's. each vrf is associated to differen namespace. When it comes o the container , the container can only see certain physical interfaces that are associated to that namespace which in turn as associated to global vrf or certain vrf. Practically in need a application running on container to send traffic on interfaces asociated with different namespaces or different vrfs. But this does not seems to be available.



Solution 1:[1]

It can be done by ip netns from host system.

I use simple scripts and i look as working (But not persistenet between container powercycle)

  1. Add networkNamespace of my container to host system (dhcp is name of my container)
pid="$(docker inspect -f '{{.State.Pid}}' "dhcp")"
mkdir -p /var/run/netns
ln -sf /proc/$pid/ns/net "/var/run/netns/dhcp"
  1. create script.sh which add vrf and assign interface to vrf
ip link add dev vrf_m_0 type vrf table 100
ip link set dev vrf_m_0 up
ip link set dev eth0 master vrf_m_0

ip link add dev vrf_m_1 type vrf table 101
ip link set dev vrf_m_1 up
ip link set dev eth1 master vrf_m_1
  1. Run script under networkNamespece
ip netns exec dhcp bash script.sh

Edit if you want persistent solution you mast add linux capability for net admin operation --cap-add NET_ADMIN and change entrypoint script to add vrf on every start

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1