Fedora 37
Sponsored Link

Podman : コンテナーの自動起動の設定2022/11/22

 
Systemd ユニットファイルを生成して、システム起動時にコンテナーが自動起動できるよう設定します。
[1] コンテナーの自動起動の設定です。
[root@dlp ~]#
podman images

REPOSITORY                         TAG               IMAGE ID      CREATED         SIZE
localhost/podman-pause             4.3.1-1668178887  9368de8f92c7  20 minutes ago  1.09 MB
srv.world/iproute                  latest            ac96369ed105  33 minutes ago  402 MB
srv.world/fedora-nginx             latest            3e184c6f4609  2 hours ago     430 MB
srv.world/fedora-httpd             latest            87f2afc7b89d  2 hours ago     458 MB
docker.io/library/mariadb          latest            28ca9ca8e298  4 days ago      416 MB
registry.fedoraproject.org/fedora  latest            885d2b38b819  11 days ago     190 MB

# コンテナー起動

[root@dlp ~]#
podman run --name fedora-nginx -d -p 80:80 srv.world/fedora-nginx
[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                          COMMAND               CREATED        STATUS            PORTS               NAMES
1037d75d2d9f  srv.world/fedora-nginx:latest  /usr/sbin/nginx -...  4 seconds ago  Up 5 seconds ago  0.0.0.0:80->80/tcp  fedora-nginx

# Systemd ユニットファイル生成

[root@dlp ~]#
podman generate systemd --new --files --name fedora-nginx

/root/container-fedora-nginx.service
[root@dlp ~]#
cat /root/container-fedora-nginx.service

# container-fedora-nginx.service
# autogenerated by Podman 4.3.1
# Tue Nov 22 16:07:49 JST 2022

[Unit]
Description=Podman container-fedora-nginx.service
Documentation=man:podman-generate-systemd(1)
Wants=network-online.target
After=network-online.target
RequiresMountsFor=%t/containers

[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=on-failure
TimeoutStopSec=70
ExecStartPre=/bin/rm \
        -f %t/%n.ctr-id
ExecStart=/usr/bin/podman run \
        --cidfile=%t/%n.ctr-id \
        --cgroups=no-conmon \
        --rm \
        --sdnotify=conmon \
        --replace \
        --name fedora-nginx \
        -d \
        -p 80:80 srv.world/fedora-nginx
ExecStop=/usr/bin/podman stop \
        --ignore -t 10 \
        --cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm \
        -f \
        --ignore -t 10 \
        --cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all

[Install]
WantedBy=default.target

[root@dlp ~]#
cp /root/container-fedora-nginx.service /usr/lib/systemd/system

# 自動起動を有効化

[root@dlp ~]#
systemctl enable container-fedora-nginx.service

Created symlink /etc/systemd/system/default.target.wants/container-fedora-nginx.service → /usr/lib/systemd/system/container-fedora-nginx.service.
[2] Pod の自動起動の設定です。
# Pod 起動

[root@dlp ~]#
podman run -dt --pod new:nginx-pod -p 80:80 srv.world/fedora-nginx
[root@dlp ~]#
podman pod ls

POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
bf3e980abc4b  nginx-pod   Running     13 seconds ago  eda07bd44091  2

# Systemd ユニットファイル生成

[root@dlp ~]#
podman generate systemd --files --name nginx-pod

/root/pod-nginx-pod.service
/root/container-infallible_lewin.service
[root@dlp ~]#
cp /root/pod-nginx-pod.service /root/container-infallible_lewin.service /usr/lib/systemd/system

# 自動起動を有効化

[root@dlp ~]#
systemctl enable pod-nginx-pod.service container-infallible_lewin.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/default.target.wants/container-infallible_lewin.service → /usr/lib/systemd/system/container-infallible_lewin.service.
関連コンテンツ