How to bind a docker container and its virtual ethernet interface in a host

Each container is associated with a virtual Ethernet interface on a named host veth7K7R1J

. I can find it in /sys/class/net/veth7K7R1J/statistics

. But I'm wondering how to find this relationship. Is there a way to do this?

+3


source to share


1 answer


Given eth0

inside the container, you need to find the peer_ifindex (which you can do with ethtool -S

) and then define that interface index on the host (s ip link

). So:

$ docker run -it --rm ubuntu:14.04.2 bash
root@07e330775e98:/# apt-get update && apt-get install -y ethtool
[...]
root@07e330775e98:/# ethtool -S eth0
NIC statistics:
     peer_ifindex: 875

      



Then on the host again:

$ ip link | grep '^875:'
875: vethdd8c173: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP

      

+4


source







All Articles