dockerps hinzugefügt
Add Command dockerps for better cotnainer listing
This commit is contained in:
commit
4acf988de5
1 changed files with 45 additions and 0 deletions
45
dockerps
Normal file
45
dockerps
Normal file
|
@ -0,0 +1,45 @@
|
|||
dockerps() {
|
||||
GREEN="\033[0;32m"; RED="\033[0;31m"; YELLOW="\033[0;33m"; NC="\033[0m"
|
||||
|
||||
docker ps --format '{{.Names}}\t{{.Image}}\t{{.Status}}' | \
|
||||
awk -F'\t' -v green="$GREEN" -v red="$RED" -v yellow="$YELLOW" -v nc="$NC" '
|
||||
function lastpos(s, ch, i,p){p=0; for(i=1;i<=length(s);i++) if(substr(s,i,1)==ch) p=i; return p}
|
||||
{
|
||||
name=$1; img=$2; stat=$3;
|
||||
|
||||
# --- Health extrahieren ---
|
||||
health="unknown"; color=yellow;
|
||||
if (stat ~ /\(healthy\)/) {health="healthy"; color=green}
|
||||
else if (stat ~ /\(unhealthy\)/) {health="unhealthy"; color=red}
|
||||
|
||||
# --- Image/Version parsen ---
|
||||
image=img; ver="none";
|
||||
if (img ~ /@/) {
|
||||
split(img, a, "@")
|
||||
image=a[1]; ver=a[2]
|
||||
if (ver ~ /^sha256:/) { sub(/^sha256:/,"",ver); ver="sha256:" substr(ver,1,12) }
|
||||
} else {
|
||||
ls=lastpos(img,"/"); lc=lastpos(img,":")
|
||||
if (lc>ls && lc>0) { image=substr(img,1,lc-1); ver=substr(img,lc+1) }
|
||||
}
|
||||
|
||||
data[NR,"name"]=name
|
||||
data[NR,"image"]=image
|
||||
data[NR,"ver"]=ver
|
||||
data[NR,"health"]=health
|
||||
data[NR,"color"]=color
|
||||
|
||||
if (length(name)>max_name) max_name=length(name)
|
||||
if (length(image)>max_image) max_image=length(image)
|
||||
if (length(ver)>max_ver) max_ver=length(ver)
|
||||
}
|
||||
END {
|
||||
# Header
|
||||
printf "%-"max_name"s %-"max_image"s %-"max_ver"s %s\n", "NAMES", "IMAGE", "VERSION", "STATUS"
|
||||
for (i=1; i<=NR; i++) {
|
||||
printf "%-"max_name"s %-"max_image"s %-"max_ver"s %s%-10s%s\n",
|
||||
data[i,"name"], data[i,"image"], data[i,"ver"],
|
||||
data[i,"color"], data[i,"health"], nc
|
||||
}
|
||||
}'
|
||||
}
|
Loading…
Add table
Reference in a new issue