Podman 容器设置开机启动
使用podman的时候,已经知道他没有额外的守护进程,这个时候需要通过systemd实现容器的开机自动启动
假设你的服务器目前已经生成了3个容器,容器的名称分别是nginx1、nginx2、nginx3。注意三个容器一定要逐个启动,否则就会报错。
1.创建service文件
cd /usr/lib/systemd/system/
touch podman-container1.service
touch podman-container2.service
touch podman-container3.service
1234
1.1 三个service文件内容如下:
###podman-container1.service###
[Unit]
Description=Podman container1
[Service]
Type=simple
ExecStart=/usr/bin/podman start -a nginx1
ExecStop=/usr/bin/podman stop -t 10 nginx1
[Install]
WantedBy=multi-user.target
1234567891011
###podman-container2.service###
[Unit]
Description=Podman container2
After=network.target
After=network-online.target
After=podman-container1.service
[Service]
Type=simple
ExecStart=/usr/bin/podman start -a nginx2
ExecStop=/usr/bin/podman stop -t 20 nginx2
[Install]
WantedBy=multi-user.target
1234567891011121314
###podman-container3.service###
[Unit]
Description=Podman container3
After=network.target
After=network-online.target
After=podman-container2.service
[Service]
Type=simple
ExecStart=/usr/bin/podman start -a nginx3
ExecStop=/usr/bin/podman stop -t 22 nginx3
[Install]
WantedBy=multi-user.target
1234567891011121314
2.设置开机启动:
systemctl enable podman-container1.service
systemctl enable podman-container2.service
systemctl enable podman-container3.service
123
3.重启server验证
reboot
docker ps -a
专注运维开发和开源技术!!