2.2. 获取或构建 bootc 镜像


获取现有 bootc 镜像或创建一个镜像,然后将该镜像发布到远程 registry 中以供使用。

2.2.1. 为 MicroShift 获取公布的 bootc 镜像

您可以使用 MicroShift 容器镜像为 RHEL 安装镜像模式。

先决条件

  • 您有一个 x86_64 或 AArch64 平台。
  • 您可以访问 registry.redhat.io registry。

流程

  1. 导航到 红帽生态系统目录
  2. 使用 microshift-bootc 关键字搜索 MicroShift 容器镜像。
  3. 打开 MicroShift 容器镜像的容器镜像页面。
  4. 请参阅 OverviewTechnical Information 选项卡,以获取有关镜像的更多详细信息。
  5. 选择 Get this image 选项卡来查看下载镜像的说明。
  6. 使用以下命令登录到 registry,获取 x86_64 和 AArch64 平台上的最新镜像:

    $ sudo podman login registry.redhat.io
    Copy to Clipboard Toggle word wrap
  7. 运行以下命令来下载 bootc 镜像:

    $ podman pull registry.redhat.io/openshift4/microshift-bootc-rhel9:v4.18
    Copy to Clipboard Toggle word wrap

2.2.2. 构建 bootc 镜像

使用 Containerfile 构建包含 MicroShift 的 Red Hat Enterprise Linux (RHEL)。

重要

RHEL 的镜像模式是技术预览。不支持在生产环境中使用 bootc 镜像。

先决条件

  • 具有有效红帽订阅的 RHEL 9.4 主机,用于构建 MicroShift bootc 镜像和运行容器。
  • 您可以使用具有 sudo 权限的用户凭证登录到 RHEL 9.4 主机。
  • rhocpfast-datapath 存储库可在主机订阅中访问。存储库不一定需要在主机上启用。
  • 您有一个远程 registry,如 Red Hat quay,用于存储和访问 bootc 镜像。

流程

  1. 创建一个包含以下指令的 Containerfile :

    RHEL 镜像模式的 Containerfile 示例

    FROM registry.redhat.io/rhel9/rhel-bootc:9.4
    
    ARG USHIFT_VER=4.18
    RUN dnf config-manager \
            --set-enabled rhocp-${USHIFT_VER}-for-9-$(uname -m)-rpms \
            --set-enabled fast-datapath-for-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
    Copy to Clipboard Toggle word wrap

    重要

    在构建容器镜像时,Podman 使用容器内的主机订阅信息和存储库。如果主机上没有 rhocpfast-datapath 存储库,则构建会失败。

  2. 设置 PULL_SECRET 环境变量:

    $ PULL_SECRET=~/.pull-secret.json
    Copy to Clipboard Toggle word wrap
  3. 配置 USER_PASSWD 环境变量:

    $ USER_PASSWD=<redhat_user_password> 
    1
    Copy to Clipboard Toggle word wrap
    1
    <redhat_user_password& gt; 替换为您的密码。
  4. 配置 IMAGE_NAME 环境变量:

    $ IMAGE_NAME=microshift-4.18-bootc
    Copy to Clipboard Toggle word wrap
  5. 运行以下 image build 命令创建本地 bootc 镜像:

    $ sudo podman build --authfile "${PULL_SECRET}" -t "${IMAGE_NAME}" \
        --build-arg USER_PASSWD="${USER_PASSWD}" \
        -f Containerfile
    Copy to Clipboard Toggle word wrap
    重要

    在镜像构建过程中如何使用 secret:

    • 需要 podman-- authfile 参数从 registry.redhat.io registry 中拉取基础 rhel-bootc:9.4 镜像。
    • build USER_PASSWD 参数用于为 redhat 用户设置密码。

验证

  1. 运行以下命令验证本地 MicroShift bootc 镜像是否已创建:

    $ sudo podman images "${IMAGE_NAME}"
    Copy to Clipboard Toggle word wrap

    输出示例

    REPOSITORY                       TAG         IMAGE ID      CREATED        SIZE
    localhost/microshift-4.18-bootc  latest      193425283c00  2 minutes ago  2.31 GB
    Copy to Clipboard Toggle word wrap

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat