Podman 设置开机自启容器

2022 年 2 月 9 日 2154 点热度 0 人点赞 1 条评论

在 Podman 中,原 Docker 使用的–restart 参数已经无效。要为一个名叫 web 的容器设置开机自启动,可采用以下做法。

podman generate systemd --restart-policy always -t 300 -n -f web

其中,–restart-policy 参数设置重启策略,-t 参数设置超时时间。末尾跟的是容器名。

mv container-web.service /etc/systemd/system/

将建立好的 container-web 服务移到/etc/systemd/system/ 目录下面。

systemctl daemon-reload

重载服务配置文件。

restorecon -RvF container-web.service

container-web 服务打上标记,防止 SELinux 作怪。

systemctl enable container-web.service --now

启用 container-web 服务。

到这里,开机自启就做好了,可通过 systemctl 进行管理。

耗子

练习时长 4 年半的个人程序员 喜欢 PHP 、 Go 、 Vue 和 Python Music~

文章评论

Loading...