Última atividade 1 month ago

Erreur32's Avatar Erreur32 revisou este gist 6 months ago. Ir para a revisão

Sem alterações

Erreur32's Avatar Erreur32 revisou este gist 1 year ago. Ir para a revisão

1 file changed, 31 insertions

show_netowrk-ip_docker.sh(arquivo criado)

@@ -0,0 +1,31 @@
1 + #!/bin/bash
2 +
3 + # show_netowrk-ip_docker.sh
4 + # By Erreur32 2025
5 +
6 + # Fonction pour afficher un tableau bien aligné
7 + function 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
26 + networks=$(docker network ls --format '{{.Name}}')
27 +
28 + # Afficher les résultats
29 + for net in $networks; do
30 + print_table "$net"
31 + done
Próximo Anterior