使⽤podman的时候,已经知道他没有额外的守护进程,这个时候需要通过systemd实现容器的开机⾃动启动
假设你的服务器⽬前已经⽣成了3个容器,容器的名称分别是nginx1、nginx2、nginx3。注意三个容器⼀定要逐个启动,否则就会报错。
1.创建service⽂件
cd /usr/lib/systemd/system/
touch podman-container1.servicetouch podman-container2.servicetouch podman-container3.service1234
1.1 三个service⽂件内容如下:
###podman-container1.service###[Unit]
Description=Podman container1
[Service]Type=simple
ExecStart=/usr/bin/podman start -a nginx1ExecStop=/usr/bin/podman stop -t 10 nginx1[Install]
WantedBy=multi-user.target1234567891011
###podman-container2.service###[Unit]
Description=Podman container2After=network.target
After=network-online.target
After=podman-container1.service
[Service]Type=simple
ExecStart=/usr/bin/podman start -a nginx2ExecStop=/usr/bin/podman stop -t 20 nginx2[Install]
WantedBy=multi-user.target1234567891011121314
###podman-container3.service###[Unit]
Description=Podman container3After=network.target
After=network-online.target
After=podman-container2.service
[Service]Type=simple
ExecStart=/usr/bin/podman start -a nginx3ExecStop=/usr/bin/podman stop -t 22 nginx3[Install]
WantedBy=multi-user.target1234567891011121314
2.设置开机启动:
systemctl enable podman-container1.servicesystemctl enable podman-container2.servicesystemctl enable podman-container3.service123
3.重启server验证
reboot
docker ps -a
因篇幅问题不能全部显示,请点此查看更多更全内容