2.2. 构建容器镜像
要使用 Containerfile 中的指令构建镜像,请使用 podman build 命令。
先决条件
-
container-tools元数据包已安装。
流程
创建
Containerfile:cat Containerfile FROM registry.redhat.io/rhel10/rhel-bootc:latest RUN dnf -y install cloud-init && \ ln -s ../cloud-init.target /usr/lib/systemd/system/default.target.wants && \ ln -s ../cloud-init.target /usr/lib/systemd/system/default.target.wants && \ dnf clean all dnf clean all$ cat Containerfile FROM registry.redhat.io/rhel10/rhel-bootc:latest RUN dnf -y install cloud-init && \ ln -s ../cloud-init.target /usr/lib/systemd/system/default.target.wants && \ dnf clean allCopy to Clipboard Copied! Toggle word wrap Toggle overflow 这个
Containerfile示例添加了cloud-init工具,因此它可以自动获取 SSH 密钥,并运行基础设施中的脚本,也可以从实例元数据中收集配置和 secret。例如,您可以将此容器镜像用于预生成的 AWS 或 KVM 客户机操作系统。使用当前目录中的
Containerfile构建<image>镜像:podman build -t quay.io/<namespace>/<image>:<tag> .
$ podman build -t quay.io/<namespace>/<image>:<tag> .Copy to Clipboard Copied! Toggle word wrap Toggle overflow
验证
列出所有镜像:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/<image> latest b28cd00741b3 About a minute ago 2.1 GBCopy to Clipboard Copied! Toggle word wrap Toggle overflow