Podman 设置开机自启容器

2022年2月9日 1781点热度 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...