docker: find network interface names of containers

raw

docker-networkinterfaces.sh

1
2
3
4
5
6
7
8
#!/bin/sh
for containername in $(docker ps --format '{{.Names}}'); do
    interfacenum=$(docker exec -i $containername cat /sys/class/net/eth0/iflink)
    echo $containername
    echo -n '  '
    ip addr | grep ^$interfacenum: | sed 's/@.*$//'
done
 
raw

output.txt

$ docker-networkinterfaces 
project_thumbor_1
  25: veth8058e1b
project_webapp_1
  23: vethb322d1d
project_drupal_1
  21: vethdb75290
project_mysql-webapp_1
  13: vethf2d1724
project_redis_1
  11: veth7887969
project_mysql-webapp-phpunit_1
  15: vethd77404a
project_elasticsearch_1
  19: veth577577d
project_mysql-drupal_1
  17: vethe9bb218
Christian Weiske Christian Weiske
owner

History