Taken from https://stackoverflow.com/a/60830947/282601
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/bin/bash export containers=$(docker ps --format "{{.ID}}|{{.Names}}") export interfaces=$(ip ad); for x in $containers do export name=$(echo "$x" |cut -d '|' -f 2); export id=$(echo "$x"|cut -d '|' -f 1) export ifaceNum="$(echo $(docker exec -it "$id" cat /sys/class/net/eth0/iflink) | sed s/[^0-9]*//g):" export ifaceStr=$( echo "$interfaces" | grep $ifaceNum | cut -d ':' -f 2 | cut -d '@' -f 1); echo -e "$name: $ifaceStr"; done |