paleozogt
paleozogt

Reputation: 6563

how to set architecture when building multi-arch Docker image?

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?

Upvotes: 2

Views: 2867

Answers (1)

snehal
snehal

Reputation: 478

Use docker buildx command instead of docker build -t command. Docker build only create docker image with respective platform.

For more information refer documentation : https://www.docker.com/blog/multi-arch-images/

Upvotes: 2

Related Questions