Docker: get relation between container and interface veth

The idea is to receive the index of the next interface.

# Get veth interface:
MY_CONTAINER_NAME="mysql_server_1"
LINK_INDEX=`docker exec -it $MY_CONTAINER_NAME ip a l eth0  | awk -F ":" '{if (NR==1) print $1+1}'`
ip link ls | grep "^$LINK_INDEX" | awk -F":" '{ gsub (" ", "", $2); print $2}'

Now you can easily observe the network traffic of your container.

# for virtual ethernet device vetha41c95c 
tcpdump -nn  -i vetha41c95c -s 0 -w - "src host SOME.IP.ADDR." -c 100 | strings
    • sthieb
    • September 20th, 2016

    Thank you!

  1. No trackbacks yet.