Files
tsd_test/dnet.sh
2026-03-25 13:51:25 +00:00

25 lines
620 B
Bash
Executable File

#!/bin/bash
if [ $# -eq 0 ]; then
nw=($(docker network ls | awk 'NR>=2 {printf "%s ",$2}'))
else
nw=$@
fi
echo ${nw[@]}
for network in ${nw[@]};do
docker network ls | grep $network 1>/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
echo -e "\nNetwork $network not found!"
exit 1
fi
ids=$(docker network inspect $network | grep -E "^\s+\".{64}\"" | awk -F\" '{printf "%s ",substr($2,0,12)}')
echo -e "\nContainers in network $network:"
for id in ${ids[@]}; do
name=$(docker ps -a | grep $id | awk '{print $NF}')
echo -e "\t$id: $name"
done
shift
done