-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utility script 'dip.sh' (#12147)
Adds a useful script for printing out the IP addresses of currently running docker containers.
- Loading branch information
1 parent
92d5a37
commit 945370c
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# dip - Displays an equivalent of 'docker container ls' but | ||
# also with IP addresses. | ||
# | ||
# Source this file, then can invoke command "dip" | ||
# | ||
# | ||
# Example Output: | ||
# | ||
# NAMES ┊IP ┊STATUS ┊SIZE | ||
# triplea-database-1 ┊172.20.0.2┊Up 34 minutes (healthy)┊63B (virtual 202MB) | ||
# triplea-game-support-server-1┊172.20.0.4┊Up 20 minutes ┊32.8kB (virtual 241MB) | ||
# triplea-lobby-1 ┊172.20.0.3┊Up 20 minutes ┊32.8kB (virtual 244MB) | ||
# triplea-nginx-1 ┊172.20.0.5┊Up 20 minutes ┊2B (virtual 58.5MB) | ||
# | ||
|
||
docker_ps="$( | ||
docker ps --format 'table{{.Names}}|{{.Status}}|{{.Size}}' | | ||
tail --lines +2 | | ||
sort | ||
)" | ||
|
||
# https://stackoverflow.com/a/20686101 | ||
FORMAT='{{.Name}}|{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' | ||
|
||
ip_addresses=$( | ||
echo "$docker_ps" | | ||
cut --fields 1 --delimiter '|' | | ||
while read -r container; do | ||
docker inspect --format=$FORMAT "$container" | ||
done | | ||
sed 's|^/||' | | ||
sort | ||
) | ||
|
||
{ | ||
FM="\033[1m%s\033[0m|\033[1m%s\033[0m|\033[1m%s\033[0m|\033[1m%s\033[0m" | ||
printf "$FM\n" NAMES IP STATUS SIZE | ||
join -t "|" <(echo "$ip_addresses") <(echo "$docker_ps") | ||
} | | ||
column --separator "|" --output-separator "┊" --table |