Docker跨架构编译

Docker跨架构编译

1.启用buildx

环境暴露

1
export DOCKER_CLI_EXPERIMENTAL=enabled

验证是否开启:

1
docker buildx version

启用 binfmt_misc

如果你使用的是 Docker 桌面版(MacOS 和 Windows),默认已经启用了 binfmt_misc,可以跳过这一步。

1
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d

2.create

Docker 默认会使用不支持多 CPU 架构的构建器,我们需要手动切换。

1
docker buildx create --use --name mybuilder

3.bootstrap启动构建器

1
docker buildx inspect mybuilder --bootstrap
1
2
3
4
5
6
7
8
9
10
11
12
docker buildx inspect mybuilder --bootstrap
[+] Building 0.7s (1/1) FINISHED
=> [internal] booting buildkit 0.7s
=> => starting container buildx_buildkit_mybuilder0 0.7s
Name: mybuilder
Driver: docker-container

Nodes:
Name: mybuilder0
Endpoint: unix:///var/run/docker.sock
Status: running
Platforms: linux/arm64, linux/amd64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6

4.构建镜像buildx

需要提前通过 docker login 命令登录认证 Docker Hub。

1
docker buildx build -t aa/aa --platform=linux/arm,linux/arm64,linux/amd64,linux/386,linux/arm/v7 . --push
1
docker buildx build -t qqfirst/mariadb --platform=linux/arm,linux/arm64,linux/amd64,linux/386 . --push
作者

舰长胡椒

发布于

2022-09-03

更新于

2023-10-13

许可协议

评论