Summary

Docker 使用 buildx 结合以下几种方式构建多架构镜像,详细参考 Building multi-platform images

  1. Using the QEMU emulation support in the kernel
  2. Building on multiple native nodes using the same builder instance
  3. Using a stage in Dockerfile to cross-compile to different architectures

注:目前看下来,第三种和第一种都是利用了 qemu 的特性

QEMU + binfmt-misc

QEMU allows us to execute binaries from other architectures, and binfmt-misc is the mechanism that maps those binaries (based on their magic bytes) to the appropriate QEMU user-space command.

QEMU 提供执行异构可执行文件的能力,binfmt-misc 标准化可执行文件以适配 QEMU 执行

1
docker buildx build --platform linux/amd64,linux/arm64 .

builder nodes

指定构建的节点,加快构建速度

1
2
3
4
5
# add local
docker buildx create --append --name multiarch-builder unix:///var/run/docker.sock
# add remote different arch
docker buildx create --append --name multiarch-builder ssh://user@arm64-host
docker buildx use multiarch-builder

Further

References