#!/bin/bash set -e echo "🔍 Ermittele Benutzerrechte für Docker-Container mit Volumes …" echo containers=$(docker ps --format '{{.Names}}') for container in $containers; do echo "📦 Container: $container" # UID/GID aus dem Container lesen uid=$(docker exec "$container" sh -c 'id -u 2>/dev/null' || echo "❌") gid=$(docker exec "$container" sh -c 'id -g 2>/dev/null' || echo "❌") if [[ "$uid" == "❌" || "$gid" == "❌" ]]; then echo " ❗ Konnte UID/GID nicht ermitteln. Container nutzt evtl. kein POSIX-System oder keine Shell." continue fi # Volumes auslesen mounts=$(docker inspect "$container" --format '{{range .Mounts}}{{println .Source "->" .Destination}}{{end}}') if [[ -z "$mounts" ]]; then echo " ℹ️ Keine gemounteten Host-Verzeichnisse gefunden." continue fi echo " 🧾 UID:GID = $uid:$gid" echo " 📁 Empfohlene chown-Befehle:" while read -r line; do host_path=$(echo "$line" | awk '{print $1}') container_path=$(echo "$line" | awk '{print $3}') echo " sudo chown -R $uid:$gid \"$host_path\" # für $container_path" done <<< "$mounts" echo done