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
。