第 2 章 构建和测试 RHEL bootc 镜像
以下流程使用 Podman 来构建和测试您的容器镜像。您也可以使用其他工具,如 OpenShift Container Platform。有关使用容器配置 RHEL 系统的更多信息,请参阅 rhel-bootc-examples 存储库。
图 2.1. 使用 Containerfile 中的指令构建镜像,测试容器,将镜像推送到 registry,并与其他人共享
通用 Containerfile 结构如下:
FROM registry.redhat.io/rhel9/rhel-bootc:latest
RUN dnf -y install [software] [dependencies] && dnf clean all
ADD [application]
ADD [configuration files]
RUN [config scripts]
可以在 Containerfile 和 Dockerfile 中使用的命令一样。
但是,当将 rhel-9-bootc 镜像安装到系统时,Containerfile 中的以下命令会被忽略:
-
ENTRYPOINT和CMD(OCI:Entrypoint/Cmd):您可以设置CMD /sbin/init。 -
ENV(OCI:Env): 更改systemd配置以配置全局系统环境。 -
EXPOSE(OCI:exposePorts):它独立于系统防火墙和运行时网络功能。 -
USER(OCI:User):配置 RHEL bootc 中的单个服务,以作为非特权用户运行。
rhel-9-bootc 容器镜像重复利用 OCI 镜像格式。
-
rhel-9-bootc容器镜像在安装到系统时会忽略容器配置部分(Config)。 -
当使用容器运行时(如
podman或docker)运行此镜像时,rhel-9-bootc容器镜像不会忽略容器配置部分(Config)。
此发行版本不支持构建自定义 rhel-bootc 基础镜像。
2.1. 构建容器镜像 复制链接链接已复制到粘贴板!
使用 podman build 命令,使用 Containerfile 中的指令构建镜像。
先决条件
-
container-tools元数据包已安装。
流程
创建
Containerfile:$ cat Containerfile FROM registry.redhat.io/rhel9/rhel-bootc:latest RUN dnf -y install cloud-init && \ ln -s ../cloud-init.target /usr/lib/systemd/system/default.target.wants && \ dnf clean all这个
Containerfile示例添加了cloud-init工具,因此它可以自动获取 SSH 密钥,并运行基础设施中的脚本,也可以从实例元数据中收集配置和 secret。例如,您可以将此容器镜像用于预生成的 AWS 或 KVM 客户机操作系统。使用当前目录中的
Containerfile构建<image>镜像:$ podman build -t quay.io/<namespace>/<image>:<tag> .
验证
列出所有镜像:
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/<image> latest b28cd00741b3 About a minute ago 2.1 GB