A Docker image based on Ubuntu 20.04, with software installed including:
To support Apple Silicon (arm64) and other platforms, we use Docker's buildx
with QEMU for emulation. Instructions for setup on your development machine follow
(assumes Ubuntu >= 20.04 and Docker is already installed).
sudo apt update
sudo apt install -y qemu-user-static
Provides the necessary emulators so you can build arm64
images on an amd64
machine.
Ensure Docker CLI experimental features are enabled:
mkdir -p ~/.docker
echo '{ "experimental": "enabled" }' > ~/.docker/config.json
(Often unnecessary with recent Docker versions, but can help avoid warnings.)
We recommend creating a named builder to avoid interfering with your default Docker setup.
docker buildx create --name multiarch-builder
To list available builders and see their status:
docker buildx ls
Once created, you can explicitly use this builder for multi-platform builds without setting it as the default:
docker buildx build --builder=multiarch-builder --platform=linux/amd64,linux/arm64 -t yourimage:tag .
Add --push
if you're building for multiple platforms and want to push to a remote registry. Without --push
, you can only export a single-platform image to the local Docker daemon using --load
.
If the builder isn't already bootstrapped (you’ll see a warning when building), you can do:
docker buildx inspect multiarch-builder --bootstrap
Once this setup is done, you can build multi-platform images like so:
docker buildx build \
--builder=multiarch-builder \
--platform=linux/amd64,linux/arm64 \
-t yourdockerhubuser/yourimage:dev \
.
Or push directly to your registry:
docker buildx build \
--builder=multiarch-builder \
--platform=linux/amd64,linux/arm64 \
-t ghcr.io/yourorg/yourimage:dev \
--push \
.
With recent versions of Docker, you can test images by specifying a platform to run on, e.g.
docker -D run --rm -it \
--platform linux/arm64 adstewart/pandoc:0.7
Adapted from (inter alia) Jan Philip Bernius's docker-pandoc
,
https://github.com/jpbernius/docker-pandoc.