Fedora 43

Podman : Generate Systemd unit file2025/11/12

 

It's possible to generate Systemd unit file and set auto-starting for containers.

[1] Configure container service by using Quadlet.
[root@dlp ~]#
podman images

REPOSITORY                         TAG         IMAGE ID      CREATED            SIZE
srv.world/iproute                  latest      126eb1cb6c14  17 minutes ago     279 MB
docker.io/library/root-web         latest      fdd007dce795  24 minutes ago     346 MB
srv.world/fedora-nginx             latest      78a532c42789  54 minutes ago     346 MB
srv.world/fedora-httpd             latest      9681aa9061c7  About an hour ago  349 MB
docker.io/library/mariadb          latest      7418b34b3691  30 hours ago       335 MB
registry.fedoraproject.org/fedora  latest      a9005aba99b1  2 days ago         186 MB

# file name ⇒ (any name).container

[root@dlp ~]#
vi /etc/containers/systemd/fedora-nginx.container
[Unit]
Description=Nginx container
After=local-fs.target

[Container]
# any name
ContainerName=fedora-nginx
# container image to be used
Image=srv.world/fedora-nginx
# port
PublishPort=80:80

[Service]
Restart=always

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

[root@dlp ~]#
systemctl daemon-reload

[root@dlp ~]#
systemctl start fedora-nginx.service
[2] Configure pod service by using Quadlet.
[root@dlp ~]#
podman images

REPOSITORY                         TAG         IMAGE ID      CREATED            SIZE
srv.world/iproute                  latest      126eb1cb6c14  18 minutes ago     279 MB
docker.io/library/root-web         latest      fdd007dce795  25 minutes ago     346 MB
srv.world/fedora-nginx             latest      78a532c42789  55 minutes ago     346 MB
srv.world/fedora-httpd             latest      9681aa9061c7  About an hour ago  349 MB
docker.io/library/mariadb          latest      7418b34b3691  30 hours ago       335 MB
registry.fedoraproject.org/fedora  latest      a9005aba99b1  2 days ago         186 MB

# create pod configuration file
# format is the same as Kubernetes

[root@dlp ~]#
vi /etc/containers/systemd/nginx-pod.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-pod
  labels:
    name: nginx-pod
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-pod
  template:
    metadata:
      labels:
        app: nginx-pod
    spec:
      containers:
      - name: nginx-pod
        image: fedora-nginx
        ports:
          - name: web
            containerPort: 80

# file name ⇒ (any name).kube

[root@dlp ~]#
vi /etc/containers/systemd/nginx-pod.kube
[Unit]
Description=Web service pod
After=local-fs.target

[Kube]
Yaml=/etc/containers/systemd/nginx-pod.yml
PublishPort=80:80

[Service]
Restart=always

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

[root@dlp ~]#
systemctl daemon-reload

[root@dlp ~]#
systemctl start nginx-pod.service
Matched Content