第8章 bootc イメージをゼロから作成する


bootc イメージをゼロから作成することで、基盤となるイメージコンテンツを制御し、システム環境を要件に合わせてカスタマイズできます。

bootc-base-imagectl コマンドを使用すると、既存の bootc ベースイメージをビルド環境として使用して bootc イメージをゼロから作成することができ、ビルドプロセスに含まれるコンテンツをより細かく制御できるようになります。このプロセスではユーザー RPM が入力として使用されるので、RPM が変更された場合はイメージを再ビルドする必要があります。

カスタムベースはベースコンテナーから派生していますが、コンテナーパイプラインに組み込まない限り、デフォルトのベースイメージに加えられた変更を自動的には取り込みません。

任意の bootc コンテナーイメージで bootc-base-imagectl rechunk サブコマンドを使用できます。

カーネル管理を実行する場合は、bootc イメージをゼロから作成する必要はありません。bootc システムでのカーネル引数の管理 を参照してください。

8.1. ピン留めされたコンテンツを使用してイメージをビルドする

ベースイメージバージョンに、ロックファイルや rpm-md または yum repository などで定義された特定のバージョンのパッケージセットが含まれていることを確認するには、rpm-md または yum repository リポジトリーのスナップショットを管理するいくつかのツールを使用できます。

bootc image from scratch 機能を使用すると、ミラーリング、ピン留め、またはスナップショットされたリポジトリーコンテンツを参照しながら、ソース RPM リポジトリー内のパッケージ情報を設定およびオーバーライドできます。その結果、パッケージのバージョンとその依存関係を制御できるようになります。

たとえば、次のような状況では、パッケージのバージョンとその依存関係を制御する必要が出てくる場合があります。

  • 厳格な認証およびコンプライアンス要件があるため、特定のパッケージバージョンを使用する必要がある。
  • 重要な依存関係をサポートするために、特定のソフトウェアバージョンを使用する必要がある。

前提条件

  • 標準の bootc ベースイメージ。

手順

  • 次の例では、ピン留めされたコンテンツを含む bootc イメージをゼロから作成します。

    # Begin with a standard bootc base image that serves as a "builder" for our custom image.
    FROM registry.redhat.io/rhel10/rhel-bootc:latest
    # Configure and override source RPM repositories, if necessary. The following step is required when referencing specific content views or target mirrored/snapshotted/pinned versions of content.
    RUN rm -vf /etc/yum.repos.d
    COPY mypinnedcontent.repo /etc/yum.repos
    # Add additional repositories to apply customizations to the image. However, referencing a custom manifest in this step is not currently supported without forking the code.
    # Build the root file system by using the specified repositories and non-RPM content from the "builder" base image.
    # If no repositories are defined, the default build will be used. You can modify the scope of packages in the base image by changing the manifest between the "standard" and "minimal" sets.
    RUN /usr/libexec/bootc-base-imagectl build-rootfs --manifest=standard /target-rootfs
    # Create a new, empty image from scratch.
    FROM scratch
    # Copy the root file system built in the previous step into this image.
    COPY --from=builder /target-rootfs/ /
    # Apply customizations to the image. This syntax uses "heredocs" https://www.docker.com/blog/introduction-to-heredocs-in-dockerfiles/ to pass multi-line arguments in a more readable format.
    RUN <<EORUN
    # Set pipefail to display failures within the heredoc and avoid false-positive successful builds.
    set -xeuo pipefail
    # Install necessary packages, run scripts, etc.
    dnf -y install NetworkManager emacs
    # Remove leftover build artifacts from installing packages in the final built image.
    dnf clean all
    rm /var/{log,cache,lib}/* -rf
    EORUN
    # Define required labels for this bootc image to be recognized as such.
    LABEL containers.bootc 1
    LABEL ostree.bootable 1
    # Optional labels that only apply when running this image as a container. These keep the default entry point running under systemd.
    STOPSIGNAL SIGRTMIN+3
    CMD ["/sbin/init"]
    # Run the bootc linter to avoid encountering certain bugs and maintain content quality. Place this command last in your Containerfile.
    RUN bootc container lint
    Copy to Clipboard Toggle word wrap

検証手順

  1. イメージを保存してビルドします。

    $ podman build -t quay.io/<namespace>/<image>:<tag> . --cap-add=all --security-opt=label=type:container_runtime_t --device /dev/fuse
    Copy to Clipboard Toggle word wrap
  2. カレントディレクトリーにある Containerfile を使用して <_image_> イメージをビルドします。

    $ podman build -t quay.io/<namespace>/<image>:<tag> .
    Copy to Clipboard Toggle word wrap
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat