跨平台构建docker镜像
前言
macbook m1是arm架构的,导致我们在构建容器镜像的时候都是
生成arm架构的镜像,但是服务器一般是amd架构,因此我们需要
有一个构建跨平台镜像工具。docker官方提供的buildx就可以
实现此功能
创建新的构建器
docker buildx create --use --name mybuilder
启动构建器
docker buildx inspect mybuilder --bootstrap
查看构建器支持的架构
docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS PLATFORMS
mybuilder * docker-container
mybuilder0 unix:///var/run/docker.sock running linux/arm64, linux/amd64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
desktop-linux docker
desktop-linux desktop-linux running linux/arm64, linux/amd64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
default docker
default default running linux/arm64, linux/amd64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
构建测试应用并推送到hub
docker buildx build -t rickyxx/nginx-demo:0.2 --platform linux/arm64,linux/amd64 . --push