7.4. 从头开始生成 bootc 镜像
从自定义 RHEL bootc 默认基础容器镜像从头开始创建 bootc 镜像,以设置小的根内容。
先决条件
-
container-tools
metapackage 已安装。
流程
创建
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 文件大型层的镜像。每次更改(如推送到 registry)都会拉取客户端,会导致复制单个大 tar 文件,并增加容器镜像大小。您可以优化为较小的版本创建的容器镜像。