16.5. 在容器中运行 Buildah


流程演示了如何在容器中运行 Buildah,并根据镜像创建可正常工作的容器。

先决条件

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

流程

  1. 登录到 registry.redhat.io 注册中心:

    $ podman login registry.redhat.io
    Username: myuser@mycompany.com
    Password: <password>
    Login Succeeded!
    Copy to Clipboard Toggle word wrap
  2. 拉取并运行 registry.redhat.io/rhel10/buildah 镜像:

    # podman run --rm --device /dev/fuse -it \
      registry.redhat.io/rhel10/buildah /bin/bash
    Copy to Clipboard Toggle word wrap
    • --rm 选项会在容器退出后删除 registry.redhat.io/rhel10/buildah 镜像。
    • device 选项将主机设备添加到容器中。
    • sys_chroot - 能够更改为不同的根目录。它不包含在容器的默认功能中。
  3. 使用 registry.access.redhat.com/ubi10/ 镜像创建一个新容器:

    # buildah from registry.access.redhat.com/ubi10/
    ...
    ubi10/-working-container
    Copy to Clipboard Toggle word wrap
  4. ubi10/-working-container 容器中运行 ls / 命令:

    # buildah run --isolation=chroot ubi10/-working-container ls /
    bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv
    Copy to Clipboard Toggle word wrap
  5. 可选:列出本地存储中的所有镜像:

    # buildah images
    REPOSITORY                        TAG      IMAGE ID       CREATED       SIZE
    registry.access.redhat.com/ubi10/   latest   ecbc6f53bba0   5 weeks ago   211 MB
    Copy to Clipboard Toggle word wrap
  6. 可选:列出工作容器及其基础镜像:

    # buildah containers
    CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
    0aaba7192762     *     ecbc6f53bba0 registry.access.redhat.com/ub... ubi10/-working-container
    Copy to Clipboard Toggle word wrap
  7. 可选:将 registry.access.redhat.com/ubi10/ 镜像推送到位于 registry.example.com 上的本地注册中心:

    # buildah push ecbc6f53bba0 registry.example.com:5000/ubi10/ubi
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat