CentOS Stream 8
Sponsored Link

Podman : Generate Systemd unit file2021/05/24

 
It's possible to generate Systemd unit file and set auto-starting for containers.
[1] Generate Systemd unit file and Set auto-starting for containers.
[root@dlp ~]#
podman images

REPOSITORY              TAG     IMAGE ID      CREATED         SIZE
srv.world/centos-nginx  latest  652de3807d5d  14 seconds ago  298 MB
quay.io/centos/centos   stream8 300e315adb2f  5 months ago    217 MB

# run container

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

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

# generate Systemd unit file

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

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

# container-centos-nginx.service
# autogenerated by Podman 3.1.0-dev
# Mon May 23 11:15:16 JST 2021

[Unit]
Description=Podman container-centos-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-centos-nginx.pid %t/container-centos-nginx.ctr-id
ExecStart=/usr/bin/podman run --conmon-pidfile %t/container-centos-nginx.pid --cidfile %t/container-centos-nginx.ctr-id --cgroups=no-conmon --replace --name centos-nginx -d -p 80:80 srv.world/centos-nginx
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/container-centos-nginx.ctr-id -t 10
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/container-centos-nginx.ctr-id
PIDFile=%t/container-centos-nginx.pid
Type=forking

[Install]
WantedBy=multi-user.target default.target

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

# enable auto-starting

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

Created symlink /etc/systemd/system/multi-user.target.wants/container-centos-nginx.service → /usr/lib/systemd/system/container-centos-nginx.service.
Created symlink /etc/systemd/system/default.target.wants/container-centos-nginx.service → /usr/lib/systemd/system/container-centos-nginx.service.
[2] Set auto-starting for pods.
# run Pod

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

POD ID        NAME       STATUS   CREATED         INFRA ID      # OF CONTAINERS
e58d4c047512  nginx-pod  Running  11 seconds ago  04ec783538a3  2

# generate Systemd unit file

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

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

# enable auto-starting

[root@dlp ~]#
systemctl enable pod-nginx-pod.service container-hopeful_newton.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.
Matched Content