Ubuntu 24.04
Sponsored Link

Podman : Generate Systemd unit file2024/05/05

 
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
localhost/podman-pause     4.9.3-0          070ddb5147bc  2 hours ago   835 kB
srv.world/iproute          latest           4ef0738fb3ef  3 hours ago   123 MB
srv.world/ubuntu-nginx     latest           1b1a4d3f4f26  5 hours ago   125 MB
srv.world/ubuntu-apache2   latest           38d508336863  6 hours ago   226 MB
dlp.srv.world:5000/ubuntu  my-registry      bf3dc08bfed0  5 days ago    78.7 MB
docker.io/library/ubuntu   latest           bf3dc08bfed0  5 days ago    78.7 MB
docker.io/moby/buildkit    buildx-stable-1  1a21071780b0  9 days ago    199 MB
docker.io/library/mariadb  latest           465bc4da7f09  2 months ago  411 MB

# file name ⇒ (any name).container

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

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

[Service]
Restart=always

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

# disable apparmor profiles below

root@dlp:~#
apparmor_parser -R /etc/apparmor.d/podman

root@dlp:~#
apparmor_parser -R /etc/apparmor.d/crun

root@dlp:~#
ln -s /etc/apparmor.d/podman /etc/apparmor.d/disable/

root@dlp:~#
ln -s /etc/apparmor.d/crun /etc/apparmor.d/disable/
root@dlp:~#
systemctl daemon-reload

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

REPOSITORY                 TAG              IMAGE ID      CREATED       SIZE
localhost/podman-pause     4.9.3-0          070ddb5147bc  4 hours ago   835 kB
srv.world/iproute          latest           4ef0738fb3ef  5 hours ago   123 MB
srv.world/ubuntu-nginx     latest           1b1a4d3f4f26  8 hours ago   125 MB
srv.world/ubuntu-apache2   latest           38d508336863  8 hours ago   226 MB
dlp.srv.world:5000/ubuntu  my-registry      bf3dc08bfed0  5 days ago    78.7 MB
docker.io/library/ubuntu   latest           bf3dc08bfed0  5 days ago    78.7 MB
docker.io/moby/buildkit    buildx-stable-1  1a21071780b0  9 days ago    199 MB
docker.io/library/mariadb  latest           465bc4da7f09  2 months ago  411 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: ubuntu-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
root@dlp:~#
podman pod ls

POD ID        NAME           STATUS      CREATED         INFRA ID      # OF CONTAINERS
ad84c14026cc  nginx-pod-pod  Running     12 seconds ago  502dbb5b0814  2
Matched Content