dockercontainersdocker-network

How to Pass-through Physical NIC to Docker Container?


Is it possible to pass-through eth(n) to Docker Container without additional plugin installation?

In LXC/LXD it is easy by this command:

lxc config device add CONTAINER-NAME eth2 nic nictype=physical parent=eth2 name=eth2

Solution

  • It is possible to move network interface to the container NET NAMESPACE (example based on my experience moving SR-IOV VF interfaces to container):

    HOST_IFACE=enp4s6f5
    CONT_IFACE_NAME=eth255
    CONTAINER=debian-test
    
    NSPID=$(docker inspect --format='{{ .State.Pid }}' $CONTAINER)
    
    ip link set "$HOST_IFACE" netns "$NSPID"
    

    In case when interface name matters it is possible to change it before set up:

    ip netns exec "$NSPID" ip link set "$HOST_IFACE" name "$CONT_IFACE_NAME"
    

    Bring it up:

    ip netns exec "$NSPID" ip link set "$CONT_IFACE_NAME" up