Fedora 42
Sponsored Link

Podman : コンテナーの自動起動の設定2025/04/25

 

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

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

REPOSITORY                         TAG               IMAGE ID      CREATED         SIZE
localhost/podman-pause             5.4.2-1743552000  44beb5bc0a3a  30 minutes ago  776 kB
srv.world/iproute                  latest            aa9549af2c42  2 hours ago     258 MB
docker.io/library/root-web         latest            6b8099ee8b9d  3 hours ago     325 MB
srv.world/fedora-nginx             latest            ad26e76247bd  3 hours ago     325 MB
srv.world/fedora-httpd             latest            512d39041a55  3 hours ago     328 MB
registry.fedoraproject.org/fedora  latest            e5bf03515e92  25 hours ago    166 MB
docker.io/library/mariadb          latest            9f3d79eba61e  2 months ago    334 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
localhost/podman-pause             5.4.2-1743552000  44beb5bc0a3a  31 minutes ago  776 kB
srv.world/iproute                  latest            aa9549af2c42  2 hours ago     258 MB
docker.io/library/root-web         latest            6b8099ee8b9d  3 hours ago     325 MB
srv.world/fedora-nginx             latest            ad26e76247bd  3 hours ago     325 MB
srv.world/fedora-httpd             latest            512d39041a55  3 hours ago     328 MB
registry.fedoraproject.org/fedora  latest            e5bf03515e92  25 hours ago    166 MB
docker.io/library/mariadb          latest            9f3d79eba61e  2 months ago    334 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
関連コンテンツ