17.4 Buildah - 容器镜像构建工具
Buildah 简介
核心特性
安装 Buildah
$ sudo dnf install -y buildah基础用法示例
1. 从现有的 Dockerfile 构建镜像
2. 交互式从空镜像开始构建
3. 查看和推送镜像
最后更新于
$ sudo dnf install -y buildah最后更新于
$ sudo apt-get update
$ sudo apt-get -y install buildah$ buildah bud -t my-app:latest .# 获取一个基础镜像
$ container=$(buildah from alpine:latest)
# 获取挂载点,并查看其路径
$ mnt=$(buildah mount $container)
$ echo $mnt
/var/lib/containers/storage/overlay/xxx/merged
# 利用宿主机直接创建文件,而不需要在容器内部运行命令
$ echo "Hello Buildah" > $mnt/hello.txt
# 添加一些配置和命令
$ buildah config --cmd "cat /hello.txt" $container
# 将容器提交为镜像
$ buildah commit $container my-hello-image:latest
# 构建完成后可以卸载并清理容器上下文
$ buildah unmount $container
$ buildah rm $container# 查看本地构建的镜像
$ buildah images
# 推送镜像到 Docker Hub(注意需要先登录)
$ buildah push my-hello-image:latest docker://docker.io/username/my-hello-image:latest