Later versions of Docker expose info about the current architecture using global variables:
BUILDPLATFORM — matches the current machine. (e.g. linux/amd64)
BUILDOS — os component of BUILDPLATFORM, e.g. linux
BUILDARCH — e.g. amd64, arm64, riscv64
BUILDVARIANT — used to set ARM variant, e.g. v7
TARGETPLATFORM — The value set with --platform flag on build
TARGETOS - OS component from --platform, e.g. linux
TARGETARCH - Architecture from --platform, e.g. arm64
TARGETVARIANT
Note that you may need to export DOCKER_BUILDKIT=1
on headless machines for these to work, and they are enabled by default on Docker Desktop.
Use in conditional scripts like so:
RUN wget "http://...../${TARGETARCH}.deb"
You can even branch Dockerfiles by using ONBUILD like this:
FROM alpine as build_amd
# Intel stuff goes here
ONBUILD RUN apt-get install -y intel_software.deb
FROM alpine as build_arm
# ARM stuff goes here
ONBUILD RUN apt-get install -y arm_software.deb
# choose the build to use for the rest of the image
FROM build_${TARGETARCH}
# rest of the dockerfile follows