欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > 使用buildx构建多架构平台镜像

使用buildx构建多架构平台镜像

2024/11/30 14:38:57 来源:https://blog.csdn.net/longtds/article/details/143527382  浏览:    关键词:使用buildx构建多架构平台镜像

1. 查看buildx插件信息

比较新的docker-ce版本默认已经集成了buildx插件

[root@docker ~]# docker buildx version
github.com/docker/buildx v0.11.2 9872040
[root@docker ~]#

2. 增加多平台镜像构建支持

通过tonistiigi/binfmt:latest初始化一个基于容器的构建环境(依据官方说明):

[root@docker ~]# docker run --privileged --rm tonistiigi/binfmt --install all
Unable to find image 'tonistiigi/binfmt:latest' locally
latest: Pulling from tonistiigi/binfmt
8d4d64c318a5: Pull complete
e9c608ddc3cb: Pull complete
Digest: sha256:66e11bea77a5ea9d6f0fe79b57cd2b189b5d15b93a2bdb925be22949232e4e55
Status: Downloaded newer image for tonistiigi/binfmt:latest
installing: mips64le OK
installing: mips64 OK
installing: ppc64le OK
installing: arm64 OK
installing: arm OK
installing: s390x OK
installing: riscv64 OK
{"supported": ["linux/amd64","linux/arm64","linux/riscv64","linux/ppc64le","linux/s390x","linux/386","linux/mips64le","linux/mips64","linux/arm/v7","linux/arm/v6"],"emulators": ["qemu-aarch64","qemu-arm","qemu-mips64","qemu-mips64el","qemu-ppc64le","qemu-riscv64","qemu-s390x"]
}
[root@docker ~]#

3. 创建构建器

构建器需要什么平台根据需要配置,这里只加了amd64和arm64:

# 创建名称为mybuilder的包含linux/amd64,linux/arm64架构的构建器
[root@docker ~]# docker buildx create --name=mybuilder --bootstrap --platform=linux/amd64,linux/arm64
[+] Building 4.3s (1/1) FINISHED=> [internal] booting buildkit                                                                                                                                     4.3s=> => pulling image moby/buildkit:buildx-stable-1                                                                                                                  3.7s=> => creating container buildx_buildkit_mybuilder0                                                                                                                0.6s
mybuilder
# 列出构建器
[root@docker ~]# docker buildx ls
NAME/NODE    DRIVER/ENDPOINT             STATUS  BUILDKIT             PLATFORMS
mybuilder    docker-containermybuilder0 unix:///var/run/docker.sock running v0.12.3              linux/amd64*, linux/arm64*, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
default *    dockerdefault    default                     running v0.11.6+616c3f613b54 linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/386, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
[root@docker ~]#

4. 设置当前构建器

默认构建器是自带的default,需要设置成我们创建的mybuilder:

[root@docker ~]# docker buildx use mybuilder
[root@docker ~]# docker buildx ls
NAME/NODE    DRIVER/ENDPOINT             STATUS  BUILDKIT             PLATFORMS
mybuilder *  docker-containermybuilder0 unix:///var/run/docker.sock running v0.12.3              linux/amd64*, linux/arm64*, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
default      dockerdefault    default                     running v0.11.6+616c3f613b54 linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/386, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
[root@docker ~]#

5. 构建并推送命令

构建镜像并推送到本地harbor仓库:

[root@docker ~]# docker buildx build \-t harbor.local/library/mysql:8.0.35 \--platform linux/amd64,linux/arm64 \--push

6. 从harbor查看镜像

可以看到多镜像的显示上多了一个类型目录的图标,可以点击查看不同架构情况:
在这里插入图片描述
在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com