Podman 容器設定開機啟動
阿新 • • 發佈:2020-12-20
使用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