AlmaLinux 9
Sponsored Link

Podman : Generate Systemd unit file2023/03/01

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    latest      f556ccecaed8  2 hours ago  310 MB    latest      ffd19e5b5339  2 hours ago  251 MB  latest      d3ffa43c2567  6 days ago   196 MB   2           0d153fadf70b  2 weeks ago  24.7 MB

# run container

[root@dlp ~]#
podman run --name almalinux-nginx -d -p 80:80
[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                             COMMAND               CREATED        STATUS            PORTS               NAMES
39ba8361888a  /usr/sbin/nginx -...  4 seconds ago  Up 4 seconds ago>80/tcp  almalinux-nginx

# generate Systemd unit file

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

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

# container-almalinux-nginx.service
# autogenerated by Podman 4.0.0
# Mon Mar 14 12:58:23 JST 2022

Description=Podman container-almalinux-nginx.service

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 almalinux-nginx -d -p 80:80
ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id


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

# enable auto-starting

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

Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/container-almalinux-nginx.service.
[2] Set auto-starting for pods.
# run Pod

[root@dlp ~]#
podman run -dt --pod new:nginx-pod -p 80:80
[root@dlp ~]#
podman pod ls

POD ID        NAME        STATUS      CREATED        INFRA ID      # OF CONTAINERS
4ab1295bc57a  nginx-pod   Running     4 seconds ago  4c2b4c72a3df  2

# generate Systemd unit file

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

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

# enable auto-starting

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

Matched Content