18.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/rhel9/buildah镜像:- podman run --rm --device /dev/fuse -it \ registry.redhat.io/rhel9/buildah /bin/bash - # podman run --rm --device /dev/fuse -it \ registry.redhat.io/rhel9/buildah /bin/bash- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - 
								--rm选项会在容器退出后删除registry.redhat.io/rhel9/buildah镜像。
- 
								device选项将主机设备添加到容器中。
- 
								sys_chroot- 能够更改为不同的根目录。它不包含在容器的默认功能中。
 
- 
								
- 使用 - registry.access.redhat.com/ubi9镜像创建一个新容器:- buildah from registry.access.redhat.com/ubi9 - # buildah from registry.access.redhat.com/ubi9 ... ubi9-working-container- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- 在 - ubi9-working-container容器中运行- ls /命令:- buildah run --isolation=chroot ubi9-working-container ls / - # buildah run --isolation=chroot ubi9-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/ubi9 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... ubi9-working-container- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- 可选:将 - registry.access.redhat.com/ubi9镜像推送到- registry.example.com上的本地注册中心:- buildah push ecbc6f53bba0 registry.example.com:5000/ubi9/ubi - # buildah push ecbc6f53bba0 registry.example.com:5000/ubi9/ubi- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow