Fedora 36
Sponsored Link

Podman : コンテナーの自動起動の設定2022/05/24

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

REPOSITORY                         TAG               IMAGE ID      CREATED       SIZE
localhost/podman-pause             4.1.0-1651853754  64648fcd477f  2 hours ago   816 kB
docker.io/library/root_web         latest            e1783cd9a348  2 hours ago   467 MB
localhost/root_web                 latest            709b93cf49d3  2 hours ago   467 MB
srv.world/fedora-nginx             latest            bfad5d240798  3 hours ago   467 MB
srv.world/fedora-httpd             latest            6c88b642f75c  3 hours ago   566 MB
docker.io/library/mariadb          latest            784190069700  9 hours ago   396 MB
registry.fedoraproject.org/fedora  latest            750037c05cfe  3 months ago  159 MB
dlp.srv.world:5000/fedora          my-registry       750037c05cfe  3 months ago  159 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
dd3729d95f0d  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.1.0
# Tue May 24 12:46:45 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 --cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm -f --ignore --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
644d1d1113fd  nginx-pod   Running     3 seconds ago  97f3ec6ee996  2

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

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

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

# 自動起動を有効化

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