Last active
August 16, 2022 16:05
-
-
Save aurelijusrozenas/dca99f4e592949d4d68920d67e049a32 to your computer and use it in GitHub Desktop.
Displays docker ps list with additional column of IP address.
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
#!/bin/bash | |
# Displays docker ps list with additional column of IP address. | |
( | |
# take default docker ps output | |
docker ps "$@" | while read -r line; do | |
# replace separators with | to use later with `column` | |
echo -n "$line" | sed 's/ \{2,\}/|/g' | tr '\t' '|'; | |
containerId=$(echo $line | column | awk '{print $1}') | |
# header | |
if [ $containerId == 'CONTAINER' ]; then | |
echo -e "|IP ADDRESS" | |
else | |
# take IP from docker inpect add to the line end | |
echo -e -n '|' | |
echo $containerId | xargs --no-run-if-empty docker inspect --format='{{range $net, $conf := .NetworkSettings.Networks}}{{$net}}:{{$conf.IPAddress}} {{end}}'; | |
fi | |
done | |
) | column -t -s '|' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working for me on ubuntu 16.04. I anyone has any ideas, how to optimize it - I am all ears.