7장. 처음부터 bootc 이미지 생성
bootc 이미지를 처음부터 사용하면 기본 이미지 콘텐츠를 제어하고 시스템 환경을 요구 사항에 맞게 조정할 수 있습니다.
기존 bootc 기본 이미지를 빌드 환경으로 사용하여 bootc-base-imagectl
명령을 사용하여 빌드 프로세스에 포함된 콘텐츠를 보다 효과적으로 제어할 수 있습니다. 이 프로세스는 사용자 RPM을 입력으로 사용하므로 RPM이 변경되면 이미지를 다시 빌드해야 합니다.
사용자 정의 베이스는 기본 컨테이너에서 파생되며 컨테이너 파이프라인의 일부로 만들지 않는 한 기본 이미지에 대한 변경 사항을 자동으로 사용하지 않습니다.
bootc 컨테이너 이미지에서 bootc-base-imagectl
rechunk
하위 명령을 사용할 수 있습니다.
커널 관리를 수행하려면 처음부터 bootc 이미지를 생성할 필요가 없습니다. bootc 시스템의 커널 인수 관리를 참조하십시오.
7.1. 고정된 콘텐츠를 사용하여 이미지 빌드
기본 이미지 버전에 lockfile 또는 rpm-md
또는 yum 리포지토리에서 정의하는 정확히 특정 버전의 패키지 세트가 포함되어 있는지 확인하려면 여러 툴을 사용하여 rpm-md
또는 yum 리포지토리
리포지토리
의 스냅샷을 관리할 수 있습니다.
bootc 이미지를 처음부터
사용하면 미러링된, 고정 또는 스냅샷된 리포지토리 콘텐츠를 참조하는 동안 소스 RPM 리포지토리에서 패키지 정보를 구성하고 재정의할 수 있습니다. 결과적으로 패키지 버전과 해당 종속성을 제어할 수 있습니다.
예를 들어 다음과 같은 상황에서 패키지 버전 및 해당 종속 항목을 제어할 수 있습니다.
- 엄격한 인증 및 규정 준수 요구 사항으로 인해 특정 패키지 버전을 사용해야 합니다.
- 중요한 종속 항목을 지원하려면 특정 소프트웨어 버전을 사용해야 합니다.
사전 요구 사항
- 표준 부팅 기본 이미지입니다.
프로세스
다음 예제에서는 고정된 콘텐츠를 사용하여 처음부터 부팅 이미지를 생성합니다.
Begin with a standard bootc base image that serves as a "builder" for our custom image. 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. 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. Create a new, empty image from scratch. Copy the root file system built in the previous step into this image. 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. Set pipefail to display failures within the heredoc and avoid false-positive successful builds. Install necessary packages, run scripts, etc. Remove leftover build artifacts from installing packages in the final built image. Define required labels for this bootc image to be recognized as such. Optional labels that only apply when running this image as a container. These keep the default entry point running under systemd. Run the bootc linter to avoid encountering certain bugs and maintain content quality. Place this command last in your Containerfile.
# 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 Copied!
검증
이미지를 저장하고 빌드합니다.
podman build -t quay.io/<namespace>/<image>:<tag> . --cap-add=all --security-opt=label=type:container_runtime_t --device /dev/fuse
$ podman build -t quay.io/<namespace>/<image>:<tag> . --cap-add=all --security-opt=label=type:container_runtime_t --device /dev/fuse
Copy to Clipboard Copied! 현재 디렉터리의
Containerfile
을 사용하여 <_image_> 이미지를 빌드합니다.podman build -t quay.io/<namespace>/<image>:<tag> .
$ podman build -t quay.io/<namespace>/<image>:<tag> .
Copy to Clipboard Copied!