-
-
Save caot/beef49b771b729422c5fa0a9f8dc6242 to your computer and use it in GitHub Desktop.
Workaround script for podman rm (--force) does not work anymore ("container state improper"/"invalid argument" when unmounting) and start neither, see https://github.com/containers/podman/issues/19913
This file contains hidden or 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 | |
#set -x | |
# Define the list of containers you want to remove | |
containers=("nextcloud_redis_1" "nextcloud_db_1" "nextcloud_nc_1") | |
for container in "${containers[@]}"; do | |
echo "Now handling $container..." | |
# First attempt to forcefully remove the container | |
podman rm --force "$container" | |
# Check if the removal failed | |
if [ $? -ne 0 ]; then | |
# Extract the mount path from the error message | |
error_message=$(podman rm --force "$container" 2>&1) | |
mount_path=$(echo "$error_message" | grep -oE '/var/home/[^ ]+merged'| head -n 1) | |
echo "found mount_path=$mount_path" | |
# If a mount path was found, attempt to unmount it using tmpfs | |
if [ -n "$mount_path" ]; then | |
podman unshare mount -t tmpfs none "$mount_path" | |
podman rm --force "$container" | |
# Check if the unmounting failed due to a non-empty directory | |
if [ $? -ne 0 ]; then | |
echo "Backup/move $mount_path directory" | |
# Rename the directory if it's not empty | |
mv "$mount_path" "${mount_path}_backup" | |
# Finally, try to forcefully remove the container again | |
podman rm --force "$container" | |
fi | |
fi | |
fi | |
done |
Author
caot
commented
Mar 7, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment