Podman : コンテナーの自動起動の設定2021/07/29 |
Systemd ユニットファイルを生成して、システム起動時にコンテナーが自動起動できるよう設定します。
|
|
[1] | コンテナーの自動起動の設定です。 |
[root@dlp ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/root_web latest a5b8f841a624 38 minutes ago 340 MB srv.world/rocky-nginx latest b11bf176fd62 About an hour ago 340 MB srv.world/rocky-httpd latest 5104875e9a87 About an hour ago 342 MB docker.io/library/mariadb latest fd17f5776802 2 days ago 416 MB registry.access.redhat.com/ubi8/pause latest 330db2d74fc3 5 weeks ago 3.49 MB docker.io/rockylinux/rockylinux latest 333da17614b6 5 weeks ago 234 MB docker.io/library/registry 2 1fd8e1b0bb7e 3 months ago 26.8 MB # コンテナー起動 [root@dlp ~]# podman run --name rocky-nginx -d -p 80:80 srv.world/rocky-nginx
podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e03dfd334d99 srv.world/rocky-nginx /usr/sbin/nginx -... 7 seconds ago Up 8 seconds ago 0.0.0.0:80->80/tcp rocky-nginx # Systemd ユニットファイル生成 [root@dlp ~]# podman generate systemd --new --files --name rocky-nginx /root/container-rocky-nginx.service cat /root/container-rocky-nginx.service # container-rocky-nginx.service # autogenerated by Podman 3.0.2-dev # Thu Jul 29 16:44:06 JST 2021 [Unit] Description=Podman container-rocky-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-rocky-nginx.pid %t/container-rocky-nginx.ctr-id ExecStart=/usr/bin/podman run --conmon-pidfile %t/container-rocky-nginx.pid --cidfile %t/container-rocky-nginx.ctr-id --cgroups=no-conmon --replace --name rocky-nginx -d -p 80:80 srv.world/rocky-nginx ExecStop=/usr/bin/podman stop --ignore --cidfile %t/container-rocky-nginx.ctr-id -t 10 ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/container-rocky-nginx.ctr-id PIDFile=%t/container-rocky-nginx.pid Type=forking [Install] WantedBy=multi-user.target default.target
[root@dlp ~]#
cp /root/container-rocky-nginx.service /usr/lib/systemd/system # 自動起動を有効化 [root@dlp ~]# systemctl enable container-rocky-nginx.service Created symlink /etc/systemd/system/multi-user.target.wants/container-rocky-nginx.service → /usr/lib/systemd/system/container-rocky-nginx.service. Created symlink /etc/systemd/system/default.target.wants/container-rocky-nginx.service → /usr/lib/systemd/system/container-rocky-nginx.service. |
[2] | Pod の自動起動の設定です。 |
# Pod 起動 [root@dlp ~]# podman run -dt --pod new:nginx-pod -p 80:80 srv.world/rocky-nginx
podman pod ls POD ID NAME STATUS CREATED INFRA ID # OF CONTAINERS 65c960c84fb6 nginx-pod Running 5 seconds ago ce5918266667 2 # Systemd ユニットファイル生成 [root@dlp ~]# podman generate systemd --files --name nginx-pod /root/pod-nginx-pod.service /root/container-optimistic_haslett.service
[root@dlp ~]#
cp /root/pod-nginx-pod.service /root/container-optimistic_haslett.service /usr/lib/systemd/system # 自動起動を有効化 [root@dlp ~]# systemctl enable pod-nginx-pod.service container-optimistic_haslett.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 |