docker / buildx

Docker CLI plugin for extended build capabilities with BuildKit
Apache License 2.0
3.55k stars 481 forks source link

Question: Is it possible to enable multi-arch emulation only for specific builders? #875

Open zachary-povey opened 2 years ago

zachary-povey commented 2 years ago

Our use case for this is that we want to build some images in multi-arch and therefore require binfmt to be installed in our build environment.

However, for most of our images we are still building single-arch and don't want to enable emulation, the reason being that we do not have nor want to enable emulation in our runtime environment as this would allow containers to run non-native binaries with degraded performance. However by enabling emulation at build time, any tests that run at this point would not fail in this scenario and so we would only see problems once the containers were running in our runtime env.

So my question is, is there a way to enable qemu/binfmt emulation only for a specific builder, rather than across the whole docker system of the host?

tonistiigi commented 2 years ago

If binfmt_misc is installed in kernel it is system-wide. If it is not installed in the kernel then buildkit has builder-only fallback. There is no configuration option for the fallback and it is always enabled when non-native builds are requested.

zachary-povey commented 2 years ago

Hey @tonistiigi - thanks for getting back to me :)

So I thought this may be the case, so I got a linux machine without binfmt, installed buildx and then did the following:

$ docker buildx create --use --name multi-arch --driver docker-container --driver-opt image=moby/buildkit:master,network=host
multi-arch
$ docker buildx inspect --bootstrap
[+] Building 2.8s (1/1) FINISHED                                                                                                     
 => [internal] booting buildkit                                                                                                 2.8s
 => => pulling image moby/buildkit:master                                                                                       1.9s
 => => creating container buildx_buildkit_multi-arch0                                                                           0.9s
Name:   multi-arch
Driver: docker-container

Nodes:
Name:      multi-arch0
Endpoint:  unix:///var/run/docker.sock
Status:    running
Platforms: linux/amd64, linux/386

So the builder lists itself as only supporting native architectures, have I missed something? Is there other requirements of the host?