Skip to content

Instantly share code, notes, and snippets.

@superseb
Last active June 7, 2017 11:08
Show Gist options
  • Save superseb/a91f6c9a28796ed7e8b3f6ff77a24408 to your computer and use it in GitHub Desktop.
Save superseb/a91f6c9a28796ed7e8b3f6ff77a24408 to your computer and use it in GitHub Desktop.
Docker veth to container mapping
#!/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