Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to associate the docker container and its virtual Ethernet interface in host

Each container is associated to a virtual Ethernet interface on the host named like 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?

like image 351
che yang Avatar asked Oct 19 '25 15:10

che yang


1 Answers

Given eth0 inside the container, you need to find the peer_ifindex (which you can do with ethtool -S) and then identify that interface index on the host (with 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
like image 119
aidanhs Avatar answered Oct 21 '25 03:10

aidanhs