最終更新 1 month ago

修正履歴 7686673c71d955d742e1040cddc84fe616382d8a

show_netowrk-ip_docker.sh Raw
1#!/bin/bash
2
3# show_netowrk-ip_docker.sh
4# By Erreur32 2025
5
6# Fonction pour afficher un tableau bien aligné
7function print_table {
8 local network_name="$1"
9
10 # Récupération des conteneurs et IPs
11 local results=$(docker network inspect "$network_name" --format '{{range .Containers}}{{printf "%-30s %-20s\n" .Name .IPv4Address}}{{end}}')
12
13 # Vérifier si le réseau contient des conteneurs
14 if [[ -z "$results" ]]; then
15 echo -e "\033[33m🔹 Réseau: $network_name (Aucun conteneur attaché)\033[0m"
16 else
17 echo -e "\n\033[32m🔹 Réseau: $network_name\033[0m"
18 echo "---------------------------------------------"
19 printf "%-30s %-20s\n" "CONTAINER" "IP ADDRESS"
20 echo "---------------------------------------------"
21 echo "$results"
22 fi
23}
24
25# Lister tous les réseaux Docker
26networks=$(docker network ls --format '{{.Name}}')
27
28# Afficher les résultats
29for net in $networks; do
30 print_table "$net"
31done
32