16.5. 在容器中运行 Buildah
流程演示了如何在容器中运行 Buildah,并根据镜像创建可正常工作的容器。
先决条件
-
container-tools
元数据包已安装。
流程
登录到 registry.redhat.io 注册中心:
podman login registry.redhat.io
$ podman login registry.redhat.io Username: myuser@mycompany.com Password: <password> Login Succeeded!
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 拉取并运行
registry.redhat.io/rhel10/buildah
镜像:podman run --rm --device /dev/fuse -it \ registry.redhat.io/rhel10/buildah /bin/bash
# podman run --rm --device /dev/fuse -it \ registry.redhat.io/rhel10/buildah /bin/bash
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
--rm
选项会在容器退出后删除registry.redhat.io/rhel10/buildah
镜像。 -
device
选项将主机设备添加到容器中。 -
sys_chroot
- 能够更改为不同的根目录。它不包含在容器的默认功能中。
-
使用
registry.access.redhat.com/ubi10/
镜像创建一个新容器:buildah from registry.access.redhat.com/ubi10/
# buildah from registry.access.redhat.com/ubi10/ ... ubi10/-working-container
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在
ubi10/-working-container
容器中运行ls /
命令:buildah run --isolation=chroot 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 Copied! Toggle word wrap Toggle overflow 可选:列出本地存储中的所有镜像:
buildah images
# buildah images REPOSITORY TAG IMAGE ID CREATED SIZE registry.access.redhat.com/ubi10/ latest ecbc6f53bba0 5 weeks ago 211 MB
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 可选:列出工作容器及其基础镜像:
buildah containers
# buildah containers CONTAINER ID BUILDER IMAGE ID IMAGE NAME CONTAINER NAME 0aaba7192762 * ecbc6f53bba0 registry.access.redhat.com/ub... ubi10/-working-container
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 可选:将
registry.access.redhat.com/ubi10/
镜像推送到位于registry.example.com
上的本地注册中心:buildah push ecbc6f53bba0 registry.example.com:5000/ubi10/ubi
# buildah push ecbc6f53bba0 registry.example.com:5000/ubi10/ubi
Copy to Clipboard Copied! Toggle word wrap Toggle overflow