Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build linux/arm64 docker image on linux/amd64 host

Tags:

docker

buildx

I am running a Jenkins Alpine Linux AMD64 docker image, which I'm building myself and want to add linux/arm64 docker buildx support to it, in order to generate multi-platform images and I do not know how it supposed to work.

When I check the supported platform I get:

+ docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS  PLATFORMS
default * docker                  
  default default         running linux/amd64, linux/386

since I'm within an AMD64 image. I read that I need to install qemu for this, but I have no clue how buildx will recognize that.

The documentation is relatively bare on this at: https://docs.docker.com/buildx/working-with-buildx/

Anyone an idea how to add linux/arm64 build capability within a linux/amd64 image?

The only solution I see right now is to build an image on an actual arm64 system.

like image 814
Sam Avatar asked Dec 03 '25 00:12

Sam


1 Answers

To use buildx, make sure your Docker runtime is at least version 19.03. buildx actually comes bundled with Docker by default, but needs to be enabled by setting the environment variable DOCKER_CLI_EXPERIMENTAL.

export DOCKER_CLI_EXPERIMENTAL=enabled

If you're on Linux, you need to set up binfmt_misc. This is pretty easy in most distributions, but is even easier now that you can just run a privileged Docker container to set it up for you.

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

Create a new builder which gives access to the new multi-architecture features:

docker buildx create --use --name multi-arch-builder

Then you'll be able to build the containers with:

docker buildx build --platform=[your target platform] ...

This is the setup I use on my Jenkins pipeline.

Relevant documentation:

  • https://docs.docker.com/desktop/multi-arch/
  • In-depth tutorial: https://medium.com/@artur.klauser/building-multi-architecture-docker-images-with-buildx-27d80f7e2408
  • In-depth tutorial without medium paywall: https://nexus.eddiesinentropy.net/2020/01/12/Building-Multi-architecture-Docker-Images-With-Buildx/
like image 85
mattdibi Avatar answered Dec 05 '25 13:12

mattdibi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!