docker: list linux veth network devices of containers

revision eea595939422e0f6beab98783e45afcf346b87a1

raw

container-network-interfaces.sh

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
 

History