Let's say I have an app foo
built for many different arches (e.g, foo-arm64
, foo-amd64
, etc). I would like to make very small Docker images like so:
FROM scratch
ARG ARCH
ADD foo-$ARCH /bin/foo
ENTRYPOINT [ "/bin/foo" ]
However, when I build an image:
docker build -t foo:arm64 --platform linux/arm64 --build-arg ARCH=arm64 .
the architecture isn't correct:
docker inspect foo:arm64 | grep Arch
"Architecture": "amd64", # should be arm64??
The image arch seems to always come from the host. How can I build a Docker image with the right architecture when that differs from the host? How do the official Docker images do this?