Skip to content

Instantly share code, notes, and snippets.

@mjf
Created December 6, 2021 10:30
Show Gist options
  • Save mjf/113e5c1c8006c79e7b92cf8374274610 to your computer and use it in GitHub Desktop.
Save mjf/113e5c1c8006c79e7b92cf8374274610 to your computer and use it in GitHub Desktop.
DIP - Docker IP (petite tool to list container IP addresses)
#! /bin/sh
# DIP - Docker IP (petite tool to list container IP addresses)
# Copyright (C) 2021 Matous Jan Fialka, <https://mjf.cz>
# Released under the terms of the "MIT License"
printf -- '%-12s %-47s %-15s\n' 'CONTAINER ID' 'NAME' 'IP ADDRESS'
printf -- '------------ '
printf -- '----------------------------------------------- '
printf -- '---------------\n'
docker ps -a --format '{{.ID}}' |
grep -E "${1:-.*}" |
while read C; do
M="$(
docker inspect --format '{{.Name}}' "$C" |
sed '
s#/##
s/^\(.\{36\}\).\+\(.\{8\}\)$/\1..>\2/
'
)"
N="$(
docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' "$C" |
sort -V
)"
I=0
for A in $N; do
if [ $I -gt 0 ]; then
printf -- '%-61s %-15s\n' ' ' "$A"
else
printf -- '%-12s %-47s %-15s\n' "$C" "$M" "$A"
fi
I=$((I+1))
done
done
# vi:ft=sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment