Fedora 38
Sponsored Link

Podman : コンテナーの自動起動の設定2023/04/26

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

REPOSITORY                         TAG               IMAGE ID      CREATED         SIZE
localhost/podman-pause             4.5.0-1681486942  aaf574b56683  18 minutes ago  1.11 MB
srv.world/iproute                  latest            2e299c1e83df  24 minutes ago  392 MB
localhost/root_web                 latest            0d673ea4df4c  2 hours ago     420 MB
srv.world/fedora-nginx             latest            97533117cdc8  3 hours ago     420 MB
srv.world/fedora-httpd             latest            51d32e13e2f4  3 hours ago     477 MB
registry.fedoraproject.org/fedora  latest            c9bfca6d0ac2  6 days ago      196 MB
dlp.srv.world:5000/fedora          my-registry       c9bfca6d0ac2  6 days ago      196 MB
docker.io/library/mariadb          latest            4a632f970181  5 weeks ago     407 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
6726c8b8f5f1  srv.world/fedora-nginx:latest  /usr/sbin/nginx -...  5 seconds ago  Up 5 seconds  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.5.0
# Wed Apr 26 13:56:51 JST 2023

[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
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
68b5c0f4bd9c  nginx-pod   Running     4 seconds ago  8c6afaf7b869  2

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

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

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

# 自動起動を有効化

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