12.8. Automatically updating containers using Podman
The podman auto-update command allows you to automatically update containers according to their auto-update policy. The podman auto-update command updates services when the container image is updated on the registry. To use auto-updates, containers must be created with the --label "io.containers.autoupdate=image" label and run in a systemd unit generated by podman generate systemd --new command.
Podman searches for running containers with the "io.containers.autoupdate" label set to "image" and communicates to the container registry. If the image has changed, Podman restarts the corresponding systemd unit to stop the old container and create a new one with the new image. As a result, the container, its environment, and all dependencies, are restarted.
Starting with Podman v4.6, you can use the Quadlets that describe how to run a container in a format similar to regular systemd unit files and hides the complexity of running containers under systemd.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Start a
myubicontainer based on theregistry.access.redhat.com/ubi10/ubi-initimage:# podman run --label "io.containers.autoupdate=image" \ --name myubi -dt registry.access.redhat.com/ubi10/ubi-init top bc219740a210455fa27deacc96d50a9e20516492f1417507c13ce1533dbdcd9dOptional: List containers that are running or have exited:
# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 76465a5e2933 registry.access.redhat.com/10/ubi-init:latest top 24 seconds ago Up 23 seconds ago myubiGenerate a
systemdunit file for themyubicontainer:# podman generate systemd --new --files --name myubi /root/container-myubi.serviceCopy unit files to
/usr/lib/systemd/systemfor installing it as a root user:# cp -Z ~/container-myubi.service /usr/lib/systemd/systemReload
systemdmanager configuration:# systemctl daemon-reloadStart and check the status of a container:
# systemctl start container-myubi.service # systemctl status container-myubi.serviceAuto-update the container:
# podman auto-updateFor more information, see the
podman-generate-systemd(1), andsystemctl(1)man pages on your system.