#!/bin/bash # Remove images BY NAME for apps that are no longer deployed. NEVER `docker image prune` and never # `docker system prune`: a global cleanup on any Felhom host is forbidden, and the scratch guest is # not an exception worth making. Every removal below names one exact reference and is skipped if any # container still uses it. cat <<'SCRIPT' | ssh -o ConnectTimeout=30 demo-hp 'cat > /tmp/rc.sh; pct push 9202 /tmp/rc.sh /tmp/rc.sh >/dev/null 2>&1; pct exec 9202 -- bash /tmp/rc.sh; rm -f /tmp/rc.sh' 2>/dev/null set -u echo "free before: $(df -h /var/lib/felhom | tail -1 | awk '{print $4}')" INUSE=$(docker ps -a --format '{{.Image}}' | sort -u) N=0 for i in $(docker images --format '{{.Repository}}:{{.Tag}}' | grep -v '' | sort -u); do case "$i" in gitea.dooplex.hu/admin/felhom-controller:*|traefik:*|gtstef/filebrowser:*|registry:2|localhost:5000/drill/*) continue;; esac if echo "$INUSE" | grep -qxF "$i"; then continue; fi if docker rmi "$i" >/dev/null 2>&1; then echo " removed $i"; N=$((N+1)); fi done echo "removed $N images BY NAME (no prune was run)" echo "free after: $(df -h /var/lib/felhom | tail -1 | awk '{print $4}')" SCRIPT