Automatically update containers using Podman

With the podman auto-update command, you can 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.

Before you begin

  • The container-tools meta-package is installed.

About this task

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.

Note

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.

Procedure

  1. Start a myubi container based on the registry.access.redhat.com/ubi10/ubi-init image:
    # podman run --label "io.containers.autoupdate=image" \
    --name myubi  -dt registry.access.redhat.com/ubi10/ubi-init top
    bc219740a210455fa27deacc96d50a9e20516492f1417507c13ce1533dbdcd9d
  2. Optional: 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          myubi
  3. Generate a systemd unit file for the myubi container:
    # podman generate systemd --new --files --name myubi
    /root/container-myubi.service
  4. Copy unit files to /usr/lib/systemd/system for installing it as a root user:
    # cp -Z ~/container-myubi.service /usr/lib/systemd/system
  5. Reload systemd manager configuration:
    # systemctl daemon-reload
  6. Start and check the status of a container:
    # systemctl start container-myubi.service
    # systemctl status container-myubi.service
  7. Auto-update the container:
    # podman auto-update

    For more information, see the podman-generate-systemd(1) and systemctl(1) man pages on your system.