ph0rex
ph0rex

Reputation: 107

Docker Build automatically pick architecture

For Docker images supporting different architectures eg:

FROM whatever:arm64 or
FROM whatever:amd64

Is it possible to have Docker automatically detect the architecture on the host and pick the relevant Docker import/inheritance?

For example if I ran the docker build on an amd64 host, it would default to picking the amd64 import.

Upvotes: 1

Views: 677

Answers (1)

BMitch
BMitch

Reputation: 263906

With multi-platform images that are pushed as a manifest list to the registry, this is the default behavior. For example, if you build FROM alpine, you don't need to specify what platform you are running on for docker to build an image for your local architecture. If you are cross compiling, you can select the image based on the target platform or the platform of the build host with buildkit using --platform and the built in ARG values TARGETPLATFORM and BUILDPLATFORM:

FROM --platform=$BUILDPLATFORM alpine

That will pull the alpine image matching your build host where it would normally match the target paltform you are creating.

For more details, see the buildx documentation on multi-platform images.

Upvotes: 2

Related Questions