7.2. 使用 UBI 微镜像

您可以使用 Buildah 工具构建一个 ubi-micro 容器镜像。

先决条件

  • container-tools 元数据包已安装。

先决条件

  • containers-tool 元软件包提供的 podman 工具已安装。

流程

  1. 拉取并构建 registry.access.redhat.com/ubi8/ubi-micro 镜像:

    # microcontainer=$(buildah from registry.access.redhat.com/ubi9/ubi-micro)
  2. 挂载可正常工作的容器根文件系统:

    # micromount=$(buildah mount $microcontainer)
  3. httpd 服务安装到 micromount 目录中:

    # dnf install \
        --installroot $micromount \
        --releasever=/ \
        --setopt install_weak_deps=false \
        --setopt=reposdir=/etc/yum.repos.d/ \
        --nodocs -y \
        httpd
    # dnf clean all \
        --installroot $micromount
  4. 在工作容器中卸载根文件系统:

    # buildah umount $microcontainer
  5. 从工作容器创建 ubi-micro-httpd 镜像:

    # buildah commit $microcontainer ubi-micro-httpd

验证步骤

  1. 显示有关 ubi-micro-httpd 镜像的详情:

    # podman images ubi-micro-httpd
    localhost/ubi-micro-httpd latest 7c557e7fbe9f  22 minutes ago  151 MB