4.6. 使用 bootc-image-builder 创建 AMI 镜像,并将其上传到 AWS


从 bootc 镜像创建 Amazon Machine Image (AMI),并使用它来启动 Amazon Web Service EC2 (Amazon Elastic Compute Cloud)实例。

先决条件

  • 您已在主机机器上安装了 Podman。
  • AWS 帐户中有一个现有的 AWS S3 存储桶。
  • 您有运行 bootc-image-builder 工具的 root 访问权限,并在 --privileged 模式下运行容器,以构建镜像。
  • 您已在帐户中配置了 vmimport 服务角色,来将 AMI 导入到 AWS 帐户中。

流程

  1. 从 bootc 镜像创建磁盘镜像。

    • 在 Containerfile 中配置用户详情。确保为它分配了 sudo 访问权限。
    • 使用 Containerfile 配置中的用户构建一个自定义操作系统镜像。它会创建一个具有无密码 sudo 访问权限的默认用户。
  2. 可选:使用 cloud-init 配置机器镜像。请参阅 用户和组配置 - 使用 cloud-init 注入用户和 SSH 密钥。以下是一个示例:

    FROM registry.redhat.io/rhel9/rhel-bootc:9.4
    
    RUN dnf -y install cloud-init && \
        ln -s ../cloud-init.target /usr/lib/systemd/system/default.target.wants && \
        rm -rf /var/{cache,log} /var/lib/{dnf,rhsm}
    Copy to Clipboard Toggle word wrap
    注意

    您还可以使用 cloud-init ,使用实例元数据添加用户和其他配置。

  3. 构建 bootc 镜像。例如,要将镜像部署到 x86_64 AWS 机器,请使用以下命令:

    $ podman build -t quay.io/<namespace>/<image>:<tag> .
    $ podman push quay.io/<namespace>/<image>:<tag> .
    Copy to Clipboard Toggle word wrap
  4. 使用 bootc-image-builder 工具从 bootc 容器镜像创建一个 AMI。

    $ sudo podman run \
      --rm \
      -it \
      --privileged \
      --pull=newer \
      -v $HOME/.aws:/root/.aws:ro \
      --env AWS_PROFILE=default \
      registry.redhat.io/rhel9/bootc-image-builder:latest \
      --type ami \
      --aws-ami-name rhel-bootc-x86 \
      --aws-bucket rhel-bootc-bucket \
      --aws-region us-east-1 \
    quay.io/<namespace>/<image>:<tag>
    Copy to Clipboard Toggle word wrap
    注意

    以下标记必须一起指定。如果没有指定任何标记,AMI 被导出到 output 目录中。

    • --AWS-ami-name - AWS 中 AMI 镜像的名称
    • --AWS-bucket - 创建 AMI 时中间存储的目标 S3 存储桶名称
    • --AWS-region - 用于AWS 上传的目标区域

      bootc-image-builder 工具构建一个 AMI 镜像,并使用 AWS 凭证将其上传到 AWS s3 存储桶,以便在构建后推送并注册一个 AMI 镜像。

后续步骤

其他资源

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat