Home > database >  Docker's FROM --platform parameter doesn't care if the platform is wrong...?
Docker's FROM --platform parameter doesn't care if the platform is wrong...?

Time:07-14

I have a very simple Dockerfile here:

FROM --platform=linux/arm64 nvidia/cuda:10.1-cudnn7-runtime

and I would expect building such a thing to fail — nvidia/cuda:10.1-cudnn7-runtime doesn't have an arm64 image. Instead, it seems to transparently pull the amd64 version of the image instead...? My build command is:

docker buildx build -f ./docker/Dockerfile.wtf -t asdf --platform linux/arm64 --load --no-cache .

And when I run it on my amd64 host, it complains about the mismatch but still runs it just fine:

▶ docker run --rm -it asdf uname -a
WARNING: The requested image's platform (linux/arm64) does not match the detected host platform (linux/amd64) and no specific platform was requested
Linux 1457f3c2456a 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

How can I tell Docker/buildkit to fail if the requested platform is unavailable? Why is it succeeding despite no arm64 image being available?

CodePudding user response:

From the documentation on the FROM --platform option:

The optional --platform flag can be used to specify the platform of the image in case FROM references a multi-platform image.

The image you are referencing is not a multi-platform image:

$ docker buildx imagetools inspect nvidia/cuda:10.1-cudnn7-runtime
Name:      docker.io/nvidia/cuda:10.1-cudnn7-runtime
MediaType: application/vnd.docker.distribution.manifest.v2 json
Digest:    sha256:faa4157b1a08e88ec53a3b549f6d229a9e9c0071250a23382bac1f2dd3ddca8c

Therefore docker will use the image as is without selecting the requested platform from the multi-platform image (since the image is not multi-platform).

To make this fail, you would need to make a base image that is a multi-platform manifest with the single platform in the list, and then you'll see failures when trying to use a different platform.

  • Related