Debian 11 Bullseye
Sponsored Link

Podman : Generate Systemd unit file2021/08/28

 
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/debian-nginx      latest  37125087a75f  24 hours ago   216 MB
docker.io/library/debian    latest  fe3c5de03486  11 days ago    129 MB
docker.io/library/registry  2       1fd8e1b0bb7e  4 months ago   26.8 MB
k8s.gcr.io/pause            3.2     80d28bedfe5d  18 months ago  688 kB

# run container

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
18fce9406035  srv.world/debian-nginx  /usr/sbin/nginx -...  5 minutes ago  Up 4 seconds ago  0.0.0.0:80->80/tcp  debian-nginx

# generate Systemd unit file

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 3.0.1
# Sat Aug 28 03:44:43 CDT 2021

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

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

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

# enable auto-starting

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

Created symlink /etc/systemd/system/multi-user.target.wants/container-debian-nginx.service → /lib/systemd/system/container-debian-nginx.service.
Created symlink /etc/systemd/system/default.target.wants/container-debian-nginx.service → /lib/systemd/system/container-debian-nginx.service.
[2] Set auto-starting for pods.
# run 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
9922d274afda  nginx-pod  Running  22 seconds ago  6cf5a92a0ef0  2

# generate Systemd unit file

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

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

# enable auto-starting

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

Created symlink /etc/systemd/system/multi-user.target.wants/pod-nginx-pod.service → /lib/systemd/system/pod-nginx-pod.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/multi-user.target.wants/container-recursing_bhabha.service → /lib/systemd/system/container-recursing_bhabha.service. Created symlink /etc/systemd/system/default.target.wants/container-recursing_bhabha.service → /lib/systemd/system/container-recursing_bhabha.service.
Matched Content