9장. 처음부터 bootc 이미지 생성
기존 bootc 기본 이미지를 입력하는 RPM 패키지를 사용하여 빌드 환경으로 사용하여 처음부터 bootc 이미지를 생성할 수 있습니다. 이를 통해 기본 이미지 콘텐츠를 제어할 수 있으며 워크로드에 필요한 패키지만 포함하여 시스템 공간 사용량 및 공격 면적을 줄일 수 있습니다.
9.1. 고정된 콘텐츠를 사용하여 이미지 빌드 링크 복사링크가 클립보드에 복사되었습니다!
재현 가능한 빌드를 유지하려면 리포지토리 스냅샷 툴을 사용하여 기본 이미지를 특정 패키지 버전에 고정할 수 있습니다. 이렇게 하면 rpm-md 또는 yum 리포지토리가 프로젝트의 lockfiles와 일관되게 유지됩니다.
bootc image from scratch 사용하면 미러링된, 고정 또는 스냅샷된 리포지토리 콘텐츠를 참조하는 동안 소스 RPM 리포지토리에서 패키지 정보를 구성하고 재정의할 수 있습니다. 결과적으로 패키지 버전과 해당 종속성을 제어할 수 있습니다.
사전 요구 사항
- 표준 부팅 기본 이미지입니다.
절차
다음 예제에서는 고정된 콘텐츠를 사용하여 처음부터 부팅 이미지를 생성합니다.
# Begin with a standard bootc base image that serves as a "builder" for our custom image. FROM registry.redhat.io/rhel10/rhel-bootc:latest as builder # 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 -rvf /etc/yum.repos.d; mkdir -p /etc/yum.repos.d/ COPY mypinnedcontent.repo /etc/yum.repos.d/ # The file must be copied to the /etc/yum.repos.d/ directory. # The mypinnedcontent.repo is your standard repository that ensures that your container will always be built with the exact same versions of software, preventing unexpected bugs or security issues from new updates. # Build the root file system 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. # 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. 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
검증
이미지를 저장하고 빌드합니다.
$ podman build -t quay.io/<namespace>/<image>:<tag> . --cap-add=all --security-opt=label=type:container_runtime_t --device /dev/fuse현재 디렉터리의
Containerfile을 사용하여 <_image_> 이미지를 빌드합니다.$ podman build -t quay.io/<namespace>/<image>:<tag> .