brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker buildx builds one image for both Intel and ARM machines

Docker
~/tips/tip-docker-buildx-multi-platform

docker buildx build \

Build and push an image that runs natively on amd64 and arm64.

If you build on an Apple Silicon Mac and run on an Intel server, or the other way round, a single --platform list makes an image that works on both.

docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t registry.example.com/app:1.0 \
  --push .

Buildx builds the Dockerfile once per platform and pushes one tag that points to both. A docker pull on either machine then gets the right variant on its own. You can check the result with docker buildx imagetools inspect.

Building the other platform runs under QEMU emulation, which Docker Desktop has built in. On a Linux host you install the binfmt handlers first. Emulated steps are slow, so a heavy compile can take many times longer. For Go and Rust, cross compiling in the Dockerfile with the BUILDPLATFORM and TARGETARCH build arguments is much faster.

The default image store keeps only one platform per tag locally, which is why the example pushes straight to a registry. With the containerd image store, which Docker Desktop and newer Engine installs use, you can also --load a multi-platform image. I would test both variants once on real hardware anyway, because an image that builds is not always an image that runs.

Further reading: Multi-platform builds

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link