Podman : コンテナーの自動起動の設定2021/05/24 |
Systemd ユニットファイルを生成して、システム起動時にコンテナーが自動起動できるよう設定します。
|
|
[1] | コンテナーの自動起動の設定です。 |
[root@dlp ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE srv.world/centos-nginx latest 652de3807d5d 14 seconds ago 298 MB quay.io/centos/centos stream8 300e315adb2f 5 months ago 217 MB # コンテナー起動 [root@dlp ~]# podman run --name centos-nginx -d -p 80:80 srv.world/centos-nginx
podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a106571f35ab srv.world/centos-nginx /usr/sbin/nginx -... 5 seconds ago Up 4 seconds ago 0.0.0.0:80->80/tcp centos-nginx # Systemd ユニットファイル生成 [root@dlp ~]# podman generate systemd --new --files --name centos-nginx /root/container-centos-nginx.service cat /root/container-centos-nginx.service # container-centos-nginx.service # autogenerated by Podman 3.1.0-dev # Mon May 23 11:15:16 JST 2021 [Unit] Description=Podman container-centos-nginx.service Documentation=man:podman-generate-systemd(1) Wants=network.target After=network-online.target [Service] Environment=PODMAN_SYSTEMD_UNIT=%n Restart=on-failure TimeoutStopSec=70 ExecStartPre=/bin/rm -f %t/container-centos-nginx.pid %t/container-centos-nginx.ctr-id ExecStart=/usr/bin/podman run --conmon-pidfile %t/container-centos-nginx.pid --cidfile %t/container-centos-nginx.ctr-id --cgroups=no-conmon --replace --name centos-nginx -d -p 80:80 srv.world/centos-nginx ExecStop=/usr/bin/podman stop --ignore --cidfile %t/container-centos-nginx.ctr-id -t 10 ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/container-centos-nginx.ctr-id PIDFile=%t/container-centos-nginx.pid Type=forking [Install] WantedBy=multi-user.target default.target
[root@dlp ~]#
cp /root/container-centos-nginx.service /usr/lib/systemd/system # 自動起動を有効化 [root@dlp ~]# systemctl enable container-centos-nginx.service Created symlink /etc/systemd/system/multi-user.target.wants/container-centos-nginx.service → /usr/lib/systemd/system/container-centos-nginx.service. Created symlink /etc/systemd/system/default.target.wants/container-centos-nginx.service → /usr/lib/systemd/system/container-centos-nginx.service. |
[2] | Pod の自動起動の設定です。 |
# Pod 起動 [root@dlp ~]# podman run -dt --pod new:nginx-pod -p 80:80 srv.world/centos-nginx
podman pod ls POD ID NAME STATUS CREATED INFRA ID # OF CONTAINERS e58d4c047512 nginx-pod Running 11 seconds ago 04ec783538a3 2 # Systemd ユニットファイル生成 [root@dlp ~]# podman generate systemd --files --name nginx-pod /root/pod-nginx-pod.service /root/container-hopeful_newton.service
[root@dlp ~]#
cp /root/pod-nginx-pod.service /root/container-hopeful_newton.service /usr/lib/systemd/system # 自動起動を有効化 [root@dlp ~]# systemctl enable pod-nginx-pod.service container-hopeful_newton.service Created symlink /etc/systemd/system/multi-user.target.wants/pod-nginx-pod.service → /usr/lib/systemd/system/pod-nginx-pod.service. Created symlink /etc/systemd/system/default.target.wants/pod-nginx-pod.service → /usr/lib/systemd/system/pod-nginx-pod.service. Created symlink /etc/systemd/system/multi-user.target.wants/container-hopeful_newton.service → /usr/lib/systemd/system/container-hopeful_newton.service. Created symlink /etc/systemd/system/default.target.wants/container-hopeful_newton.service → /usr/lib/systemd/system/container-hopeful_newton.service. |
Sponsored Link |
|