openSUSE Leap 16

Podman : コンテナーの自動起動の設定2025/10/31

 

Systemd ユニットファイルを生成して、システム起動時にコンテナーが自動起動できるよう設定します。

[1] Quadlet を使用したコンテナーサービスの設定です。
dlp:~ #
podman images

REPOSITORY                           TAG               IMAGE ID      CREATED            SIZE
localhost/podman-pause               5.4.2-1755067447  fb2028d44a7e  16 minutes ago     722 kB
docker.io/library/root-web           latest            95306b8f2f91  57 minutes ago     439 MB
srv.world/iproute                    latest            b9d2eecf712e  About an hour ago  386 MB
srv.world/suse-nginx                 latest            2f5e96e113e4  2 hours ago        439 MB
srv.world/suse-httpd                 latest            155ffb9ef27d  2 hours ago        393 MB
registry.opensuse.org/opensuse/leap  latest            004d9956dc10  2 weeks ago        118 MB
docker.io/moby/buildkit              buildx-stable-1   9403964920cf  3 weeks ago        228 MB
docker.io/library/mariadb            latest            dfbea441e6fc  2 months ago       336 MB

# ファイル名 ⇒ (任意の名称).container

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

[Container]
# 任意の名称
ContainerName=suse-nginx
# 使用するコンテナーイメージ
Image=srv.world/suse-nginx
# ポート
PublishPort=80:80

[Service]
Restart=always

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

dlp:~ #
systemctl daemon-reload

dlp:~ #
systemctl start suse-nginx.service
[2] Quadlet を使用した Pod サービスの設定です。
dlp:~ #
podman images

REPOSITORY                           TAG               IMAGE ID      CREATED            SIZE
localhost/podman-pause               5.4.2-1755067447  fb2028d44a7e  17 minutes ago     722 kB
docker.io/library/root-web           latest            95306b8f2f91  59 minutes ago     439 MB
srv.world/iproute                    latest            b9d2eecf712e  About an hour ago  386 MB
srv.world/suse-nginx                 latest            2f5e96e113e4  2 hours ago        439 MB
srv.world/suse-httpd                 latest            155ffb9ef27d  2 hours ago        393 MB
registry.opensuse.org/opensuse/leap  latest            004d9956dc10  2 weeks ago        118 MB
docker.io/moby/buildkit              buildx-stable-1   9403964920cf  3 weeks ago        228 MB
docker.io/library/mariadb            latest            dfbea441e6fc  2 months ago       336 MB

# Pod 設定ファイル作成
# 書式は Kubernetes と同じ

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: suse-nginx
        ports:
          - name: web
            containerPort: 80

# ファイル名 ⇒ (任意の名称).kube

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

dlp:~ #
systemctl daemon-reload

dlp:~ #
systemctl start nginx-pod.service
関連コンテンツ