8.4. bootc イメージをゼロから生成する
カスタム RHEL bootc デフォルトベースコンテナーイメージから bootc イメージをゼロから作成し、小さなルートコンテンツセットを取得します。
前提条件
-
container-tools
メタパッケージがインストールされている。
手順
Containerfile
を作成します。以下に例を示します。The following example reuses the default base image as a "builder" image. Optionally, you can use the commented instructions to configure or override the RPM repositories in /etc/yum.repos.d to, for example, refer to pinned versions RUN rm -rf /etc/yum.repos.d/* COPY mycustom.repo /etc/yum.repos.d Create a new, empty image from scratch. Copy the root file system built in the previous step into this image. You can make arbitrary changes such as copying the systemd units and other tweaks from the baseconfig container image. This example uses the heredocs syntax, to improve and make it easy to add complex instructions, and install critical components Install networking support and SSH which are not in minimal This label is required These labels are optional but useful if you want to keep the default of running under systemd when run as a container image.
# The following example reuses the default base image as a "builder" image. Optionally, you can use the commented instructions to configure or override the RPM repositories in /etc/yum.repos.d to, for example, refer to pinned versions FROM registry.redhat.io/rhel10/rhel-bootc:latest # RUN rm -rf /etc/yum.repos.d/* # COPY mycustom.repo /etc/yum.repos.d RUN /usr/libexec/bootc-base-imagectl build-rootfs --manifest=minimal /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/ / # You can make arbitrary changes such as copying the systemd units and other tweaks from the baseconfig container image. This example uses the heredocs syntax, to improve and make it easy to add complex instructions, and install critical components RUN <<EORUN set -xeuo pipefail # Install networking support and SSH which are not in minimal dnf -y install NetworkManager openssh-server dnf clean all rm /var/{log,cache,lib}/* -rf bootc container lint EORUN # This label is required LABEL containers.bootc 1 LABEL ostree.bootable 1 # These labels are optional but useful if you want to keep the default of running under systemd when run as a container image. STOPSIGNAL SIGRTMIN+3 CMD ["/sbin/init"]
Copy to Clipboard Copied!
次のステップ
-
Containerfile
を作成すると、単一の tar ファイルの大きなレイヤーを持つイメージが取得されます。レジストリーへのプッシュ、クライアントへのプルなどのすべての変更により、単一の大きな tar ファイルがコピーされ、コンテナーイメージのサイズが増加します。作成したコンテナーイメージを小さいバージョンに最適化できます。
必要に応じて、RHEL 9.6 システムでは、rpm-ostree
を使用して大規模なイメージを取得し、小さいバージョンにサイズを変更できます。