简体   繁体   中英

Build linux/arm64 docker image on linux/amd64 host

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.

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM