2.2. 获取或构建 bootc 镜像
获取现有 bootc 镜像或创建一个镜像,然后将该镜像发布到远程 registry 中以供使用。
2.2.1. 为 MicroShift 获取公布的 bootc 镜像 复制链接链接已复制到粘贴板!
您可以使用 MicroShift 容器镜像为 RHEL 安装镜像模式。
先决条件
- 您有一个 x86_64 或 AArch64 平台。
-
您可以访问
registry.redhat.ioregistry。
流程
- 导航到 红帽生态系统目录。
-
使用
microshift-bootc关键字搜索 MicroShift 容器镜像。 - 打开 MicroShift 容器镜像的容器镜像页面。
-
请参阅
Overview和Technical Information选项卡,以获取有关镜像的更多详细信息。 -
选择
Get this image选项卡来查看下载镜像的说明。 使用以下命令登录到 registry,获取 x86_64 和 AArch64 平台上的最新镜像:
$ sudo podman login registry.redhat.io运行以下命令来下载 bootc 镜像:
$ podman pull registry.redhat.io/openshift4/microshift-bootc-rhel9:v4.19
2.2.2. 构建 bootc 镜像 复制链接链接已复制到粘贴板!
使用 Containerfile 构建包含 MicroShift 的 Red Hat Enterprise Linux (RHEL)。
先决条件
- 具有有效红帽订阅的 RHEL 9.6 主机,用于构建 MicroShift bootc 镜像和运行容器。
-
您可以使用具有
sudo权限的用户凭证登录到 RHEL 9.6 主机。 -
rhocp和fast-datapath存储库可在主机订阅中访问。存储库不一定需要在主机上启用。 - 您有一个远程 registry,如 Red Hat quay,用于存储和访问 bootc 镜像。
-
您可以使用
dnf install -y container-tools命令在主机上安装container-toolsmeta-package。meta-package 包含所有容器工具,如 Podman、Buildah 和 Skopeo 以提供额外的支持和故障排除。在构建并安装镜像时,需要这些工具从红帽支持获得帮助。
流程
创建一个包含以下指令的 Containerfile :
RHEL 镜像模式的 Containerfile 示例
FROM registry.redhat.io/rhel9/rhel-bootc:9.6 ARG USHIFT_VER=4.19 RUN dnf config-manager \ --set-enabled rhocp-${USHIFT_VER}-for-rhel-9-$(uname -m)-rpms \ --set-enabled fast-datapath-for-rhel-9-$(uname -m)-rpms RUN dnf install -y firewalld microshift && \ systemctl enable microshift && \ dnf clean all # Create a default 'redhat' user with the specified password. # Add it to the 'wheel' group to allow for running sudo commands. ARG USER_PASSWD RUN if [ -z "${USER_PASSWD}" ] ; then \ echo USER_PASSWD is a mandatory build argument && exit 1 ; \ fi RUN useradd -m -d /var/home/redhat -G wheel redhat && \ echo "redhat:${USER_PASSWD}" | chpasswd # Mandatory firewall configuration RUN firewall-offline-cmd --zone=public --add-port=22/tcp && \ firewall-offline-cmd --zone=trusted --add-source=10.42.0.0/16 && \ firewall-offline-cmd --zone=trusted --add-source=169.254.169.1 # Create a systemd unit to recursively make the root filesystem subtree # shared as required by OVN images RUN cat > /etc/systemd/system/microshift-make-rshared.service <<'EOF' [Unit] Description=Make root filesystem shared Before=microshift.service ConditionVirtualization=container [Service] Type=oneshot ExecStart=/usr/bin/mount --make-rshared / [Install] WantedBy=multi-user.target EOF RUN systemctl enable microshift-make-rshared.service
在构建容器镜像时,Podman 使用容器内的主机订阅信息和存储库。如果主机上没有 rhocp 和 fast-datapath 存储库,则构建会失败。
设置
PULL_SECRET环境变量:$ PULL_SECRET=~/.pull-secret.json配置
USER_PASSWD环境变量:$ USER_PASSWD=<redhat_user_password>1 - 1
- 将 <redhat_user_password& gt; 替换为您的密码。
配置
IMAGE_NAME环境变量:$ IMAGE_NAME=microshift-4.19-bootc运行以下 image build 命令创建本地 bootc 镜像:
$ sudo podman build --authfile "${PULL_SECRET}" -t "${IMAGE_NAME}" \ --build-arg USER_PASSWD="${USER_PASSWD}" \ -f Containerfile重要在镜像构建过程中如何使用 secret:
-
需要 podman--
authfile参数从registry.redhat.ioregistry 中拉取基础rhel-bootc:9.6镜像。 -
build
USER_PASSWD参数用于为redhat用户设置密码。
-
需要 podman--
验证
运行以下命令验证本地 MicroShift bootc 镜像是否已创建:
$ sudo podman images "${IMAGE_NAME}"输出示例
REPOSITORY TAG IMAGE ID CREATED SIZE localhost/microshift-4.19-bootc latest 193425283c00 2 minutes ago 2.31 GB