Last active
June 7, 2017 11:08
-
-
Save superseb/a91f6c9a28796ed7e8b3f6ff77a24408 to your computer and use it in GitHub Desktop.
Docker veth to container mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Credits to https://superuser.com/a/1183520 | |
for container in $(docker ps -q); do | |
if docker exec -t $container which sh > /dev/null 2>&1; then | |
iflink=`docker exec -it $container sh -c 'cat /sys/class/net/eth0/iflink'` | |
iflink=`echo $iflink|tr -d '\r'` | |
veth=`grep -l $iflink /sys/class/net/veth*/ifindex` | |
veth=`echo $veth|sed -e 's;^.*net/\(.*\)/ifindex$;\1;'` | |
echo $container:$veth | |
else | |
echo "Can't retrieve info for $container" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment