Updating Podman containers

April 07, 2023

Overview

I wanted to document the steps to quickly update Podman containers. I’m sure this could be scripted for a sort of automatic update if desired.

Updating Podman images/containers

Here is an example for updating a SABnzbd container. Some of the file locations and commands will vary slightly depending on if you’re running Podman as root or not. I’ve noted those differences below.

# Stop the container, remove it, and pull new image
# If running as root, remove "--user"
systemctl --user stop sabnzbd-container.service
podman rm sabnzbd
podman pull docker.io/linuxserver/sabnzbd

# Disable/Remove the old systemd service and reload the daemon
# If running as root, remove "--user"
# If running as root, service location should be /etc/systemd/system/sabnzbd-container.service
systemctl --user disable sabnzbd-container.service
rm ~/.config/systemd/user/sabnzbd-container.service
systemctl --user daemon-reload

# Create a new container with the same configuration directory as before
# If creating as root, be sure to use sudo and not logged in with su, otherwise the PUID and PGID will not pass through correctly
podman run --detach --name sabnzbd -e PUID=1000 -e PGID=1000 -e TZ=America/New_York -p 8080:8080 -v ~/.config/sabnzbd-container:/config:Z -v /mnt/downloads:/downloads:z docker.io/linuxserver/sabnzbd

# Create/Enable a new systemd service
# If running as root, remove "--user"
# If running as root, service location should be /etc/systemd/system/sabnzbd-container.service
podman generate systemd --restart-policy=always sabnzbd > ~/.config/systemd/user/sabnzbd-container.service
systemctl --user enable sabnzbd-container.service

# Prune images that are dangling or have no associated container
podman image prune -a

Conclusion

Simple, to-the-point post. I hope it was helpful.