Podman自动更新容器镜像
Podman 自动更新容器镜像总结:
Podman 提供了 podman auto-update 命令用于自动更新容器镜像,而 Docker 则使用 Watchtower 来实现类似功能。本文介绍了使用 Podman 自动更新容器的两种方法,并以 miniserve 容器为例进行演示。
方法一:直接使用 podman auto-update
- 查看容器配置:
-
检查容器的
.container文件,确认其中包含AutoUpdate=registry配置。这等价于在 Podman Run 中使用--label io.containers.autoupdate=registry标签。 -
查看运行中的容器:
-
使用
podman ps -a命令列出所有正在运行和已停止的容器。 -
干运行自动更新:
-
使用
podman auto-update --dry-run命令检查哪些容器有可用更新。 -
执行自动更新:
-
运行
podman auto-update命令进行实际的容器更新操作。 -
查看更新后的容器状态:
-
再次使用
podman ps -a查看容器的运行状态,确认更新是否成功。 -
修剪旧镜像:
- 更新完成后,使用
podman image prune -f命令清理旧的、不再使用的镜像,以节省磁盘空间。
方法二:使用 podman-auto-update.timer
- 查看服务和定时器配置:
podman-auto-update.service定义了自动更新的服务,其ExecStart字段指定了更新命令,ExecStartPost用于更新后清理旧镜像。-
podman-auto-update.timer定义了更新的触发时间,OnCalendar=daily表示每天运行一次,RandomizedDelaySec=900添加随机延迟避免集中负载,Persistent=true确保系统重启后错过任务也能执行。 -
启用和启动定时器:
- 使用
systemctl enable podman-auto-update.timer命令启用定时器,使其在系统启动时自动加载。 -
使用
systemctl start podman-auto-update.timer命令手动启动定时器。 -
查看定时器状态:
- 使用
systemctl status podman-auto-update.timer查看定时器的当前状态,包括下次触发时间和服务执行情况。
先决条件和工具
- Podman 版本:需要 Podman v4.6 或更高版本。
- Quadlet 支持:使用 Quadlet 结合 Systemd 来优雅地管理容器。
- container-tools 组件:确保已安装该组件以支持 Podman 的完整功能。
总结
通过上述两种方法,用户可以根据需求选择适合的方式来自动更新 Podman 容器镜像。直接使用 podman auto-update 命令适合手动触发更新,而结合 systemd 的 podman-auto-update.timer 则适合定时自动更新,减少人工干预。无论是哪种方法,更新后都建议使用 podman image prune -f 清理旧镜像,保持系统整洁和高效。
Ref
https://docs.redhat.com/zh-cn/documentation/red_hat_enterprise_linux/9/html/building_running_and_managing_containers/proc_automatically-updating-containers-using-podman_assembly_porting-containers-to-systemd-using-podman?ref=xzllll.com https://xzllll.com/24112101/