14.9. 使用 systemd 自动更新容器
如章节 使用 Podman 自动更新容器 中所述,
您可以使用 podman auto-update 命令更新容器。它整合成自定义脚本,并在需要时调用。自动更新容器的另一种方法是使用预安装的 podman-auto-update.timer 和 podman-auto-update.service systemd 服务。podman-auto-update.timer 可以配置成在特定日期或时间触发自动更新。podman-auto-update.service 将来可由 systemctl 命令启动,或者可被其他 systemd 服务用作依赖项。因此,可以基于时间和事件的自动更新可以以各种方法触发,以满足单个需求和用例。
从 Podman v4.6 开始,您可以使用描述如何以类似于常规 systemd 单元文件的格式运行容器的 Quadlets,并在 systemd 下隐藏运行容器的复杂性。
先决条件
-
container-tools模块已安装。
流程
显示
podman-auto-update.service单元文件:# cat /usr/lib/systemd/system/podman-auto-update.service [Unit] Description=Podman auto-update service Documentation=man:podman-auto-update(1) Wants=network.target After=network-online.target [Service] Type=oneshot ExecStart=/usr/bin/podman auto-update [Install] WantedBy=multi-user.target default.target显示
podman-auto-update.timer单元文件:# cat /usr/lib/systemd/system/podman-auto-update.timer [Unit] Description=Podman auto-update timer [Timer] OnCalendar=daily Persistent=true [Install] WantedBy=timers.target在本例中,
podman auto-update命令在每天午夜启动。在系统启动时启用
podman-auto-update.timer服务:# systemctl enable podman-auto-update.timer启动
systemd服务:# systemctl start podman-auto-update.timer可选:列出所有计时器:
# systemctl list-timers --all NEXT LEFT LAST PASSED UNIT ACTIVATES Wed 2020-12-09 00:00:00 CET 9h left n/a n/a podman-auto-update.timer podman-auto-update.service您可以看到
podman-auto-update.timer激活了podman-auto-update.service。