Fedora 43

Podman : コンテナーの自動起動の設定2025/11/12

 

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

[1] 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

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

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

[Container]
# 任意の名称
ContainerName=fedora-nginx
# 使用するコンテナーイメージ
Image=srv.world/fedora-nginx
# ポート
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] Quadlet を使用した Pod サービスの設定です。
[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

# Pod 設定ファイル作成
# 書式は 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

# ファイル名 ⇒ (任意の名称).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
関連コンテンツ