Multi-arch images can be built using the built-in variables of buildkit
https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
TARGETPLATFORM
- platform of the build result. Eglinux/amd64
,linux/arm/v7
,windows/amd64
.TARGETOS
- OS component of TARGETPLATFORMTARGETARCH
- architecture component of TARGETPLATFORMTARGETVARIANT
- variant component of TARGETPLATFORMBUILDPLATFORM
- platform of the node performing the build.BUILDOS
- OS component of BUILDPLATFORMBUILDARCH
- architecture component of BUILDPLATFORMBUILDVARIANT
- variant component of BUILDPLATFORM
You can’t compose the Dockerfile dynamically unless you are using a template system and generate the file, but you don’t need that. Use the variables in a shell script and write the conditions there or just create multiple scripts containing the architecture in the name like install-arm64.sh
and install-amd64.sh
and execute the script like install-${TARGETARCH}.sh
.