Docker Container Volumes Information
Erscheinungsbild
#!/bin/bash
echo "Container-Volume-Zuordnung mit Größenangabe:"
echo "============================================"
docker ps -aq | while read cid; do
cname=$(docker inspect --format '{{.Name}}' "$cid" | sed 's/^\/\+//')
mounts=$(docker inspect "$cid" | jq '.[0].Mounts')
if [ "$(echo "$mounts" | jq 'length')" -gt 0 ]; then
echo "Container: $cname"
echo "$mounts" | jq -r '.[] | "\(.Type)|\(.Source)|\(.Destination)"' | while IFS="|" read -r mtype source dest; do
if [ -d "$source" ]; then
size=$(du -sh "$source" 2>/dev/null | cut -f1)
else
size="(nicht gefunden)"
fi
echo " Typ: $mtype"
echo " Quelle: $source"
echo " Mountpoint im Container: $dest"
echo " Größe: $size"
done
echo
fi
done
echo
echo
echo
echo "Container ohne Mounts:"
echo "======================"
docker ps -aq | while read cid; do
cname=$(docker inspect --format '{{.Name}}' "$cid" | sed 's/^\/\+//')
mount_count=$(docker inspect "$cid" | jq '.[0].Mounts | length')
if [ "$mount_count" -eq 0 ]; then
echo "$cname"
fi
done
Beispiel Ausgabe:
Container: containerA
Typ: bind
Quelle: /mnt/fastpool/docker/appdata/containerA
Mountpoint im Container: /app/backend/backup-data
Größe: 36K
Container: containerB
Typ: bind
Quelle: /mnt/fastpool/docker/appdata/containerB/data
Mountpoint im Container: /var/lib/data
Größe: 48M
Container ohne Mounts:
======================
containerC
containerD