Fedora 35
Sponsored Link

Podman : Generate Systemd unit file2021/11/11

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

REPOSITORY                         TAG         IMAGE ID      CREATED         SIZE
localhost/root_web                 latest      0a40f10d61ec  58 minutes ago  391 MB
srv.world/fedora-nginx             latest      f27df6dc0cf8  2 hours ago     391 MB
srv.world/fedora-httpd             latest      3b282c5eda58  2 hours ago     418 MB
docker.io/library/mariadb          latest      e2278f24ac88  25 hours ago    416 MB
registry.fedoraproject.org/fedora  latest      1b52edb08181  7 days ago      159 MB
k8s.gcr.io/pause                   3.5         ed210e3e4a5b  7 months ago    690 kB

# run container

[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
71678c011e08  srv.world/fedora-nginx:latest  /usr/sbin/nginx -...  12 seconds ago  Up 12 seconds ago  0.0.0.0:80->80/tcp  fedora-nginx

# generate Systemd unit file

[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 3.4.1
# Thu Nov 11 01:01:46 JST 2021

[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=multi-user.target default.target

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

# enable auto-starting

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

Created symlink /etc/systemd/system/multi-user.target.wants/container-fedora-nginx.service → /usr/lib/systemd/system/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] Set auto-starting for pods.
# run 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
5be9bf2528bc  nginx-pod   Running     9 seconds ago  806926971db6  2

# generate Systemd unit file

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

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

# enable auto-starting

[root@dlp ~]#
systemctl enable pod-nginx-pod.service container-agitated_chaum.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-agitated_chaum.service → /usr/lib/systemd/system/container-agitated_chaum.service.
Created symlink /etc/systemd/system/default.target.wants/container-agitated_chaum.service → /usr/lib/systemd/system/container-agitated_chaum.service.
Matched Content