Debian 12 bookworm
Sponsored Link

Podman : コンテナーの自動起動の設定2023/06/21

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

REPOSITORY                  TAG         IMAGE ID      CREATED            SIZE
localhost/podman-pause      4.3.1-0     27bd47a0cfe1  14 minutes ago     776 kB
localhost/root_web          latest      95ff1ec2c79f  20 minutes ago     158 MB
srv.world/iproute           latest      e5a651fe23a6  34 minutes ago     157 MB
srv.world/debian-nginx      latest      e2938e55cf7c  About an hour ago  158 MB
srv.world/debian-apache2    latest      f047c6f28c56  About an hour ago  260 MB
docker.io/library/mariadb   latest      99833200524a  4 days ago         410 MB
docker.io/library/registry  2           4bb5ea59f8e0  5 days ago         24.6 MB
docker.io/library/debian    latest      49081a1edb0b  8 days ago         121 MB

# コンテナー起動

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

CONTAINER ID  IMAGE                          COMMAND               CREATED         STATUS             PORTS               NAMES
e33db7f8c043  srv.world/debian-nginx:latest  /usr/sbin/nginx -...  12 seconds ago  Up 12 seconds ago  0.0.0.0:80->80/tcp  debian-nginx

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

root@dlp:~#
podman generate systemd --new --files --name debian-nginx

/root/container-debian-nginx.service
root@dlp:~#
cat /root/container-debian-nginx.service

# container-debian-nginx.service
# autogenerated by Podman 4.3.1
# Tue Jun 20 19:49:27 CDT 2023

[Unit]
Description=Podman container-debian-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 debian-nginx \
        -d \
        -p 80:80 srv.world/debian-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-debian-nginx.service /usr/lib/systemd/system

# 自動起動を有効化

root@dlp:~#
systemctl enable container-debian-nginx.service

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

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

POD ID        NAME        STATUS      CREATED        INFRA ID      # OF CONTAINERS
3eba77086aa1  nginx-pod   Running     4 seconds ago  be2100263864  2

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

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

/root/pod-nginx-pod.service
/root/container-stoic_ganguly.service
root@dlp:~#
cp /root/pod-nginx-pod.service /root/container-stoic_ganguly.service /usr/lib/systemd/system

# 自動起動を有効化

root@dlp:~#
systemctl enable pod-nginx-pod.service container-stoic_ganguly.service

Created symlink /etc/systemd/system/default.target.wants/pod-nginx-pod.service → /lib/systemd/system/pod-nginx-pod.service. Created symlink /etc/systemd/system/default.target.wants/container-stoic_ganguly.service → /lib/systemd/system/container-stoic_ganguly.service.
関連コンテンツ