Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caot/beef49b771b729422c5fa0a9f8dc6242 to your computer and use it in GitHub Desktop.
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
#!/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
@caot
Copy link
Author

caot commented Mar 7, 2024

$ sh workaround-podman-issue19913.sh
Now handling container-maildev...
WARN[0000] Unmounting container "container-maildev" while attempting to delete storage: unmounting "/home/docker/.local/share/containers/storage/overlay/884ff6a18bfdc216f835dd5cef54e1ba413a6e0a9ad961a6869c735d0252e704/merged": invalid argument 
Error: removing storage for container "container-maildev": unmounting "/home/docker/.local/share/containers/storage/overlay/884ff6a18bfdc216f835dd5cef54e1ba413a6e0a9ad961a6869c735d0252e704/merged": invalid argument
found mount_path=
$ rm -r /home/docker/.local/share/containers/storage/overlay/884ff6a18bfdc216f835dd5cef54e1ba413a6e0a9ad961a6869c735d0252e704/merged
$ sh workaround-podman-issue19913.sh
Now handling container-maildev...
container-maildev
$ /home/docker/start-container-maildev.sh
WARN[0000] Failed to mount subscriptions, skipping entry in /usr/share/containers/mounts.conf: getting host subscription data: failed to read subscriptions from "/usr/share/rhel/secrets": open /usr/share/rhel/secrets/redhat.repo: permission denied 
dc2ac7a9aa190febfbfb34cb7fbe55fea30833b835c8b08d79ae2002069b5e9a
$ podman container list
CONTAINER ID  IMAGE                             COMMAND               CREATED        STATUS                  PORTS                                           NAMES
dc2ac7a9aa19  docker.io/maildev/maildev:latest  bin/maildev --mai...  2 minutes ago  Up 2 minutes (healthy)  0.0.0.0:1025->1025/tcp, 0.0.0.0:1080->1080/tcp  container-maildev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment