Skip to content

[20.10 backport] docker pull: warn when pulled single-arch image does not match --platform#42633

Merged
thaJeztah merged 1 commit into
moby:20.10from
thaJeztah:20.10_backport_warn_on_non_matching_platform
Jul 15, 2021
Merged

[20.10 backport] docker pull: warn when pulled single-arch image does not match --platform#42633
thaJeztah merged 1 commit into
moby:20.10from
thaJeztah:20.10_backport_warn_on_non_matching_platform

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

backport of #42325
addresses docker/for-mac#5625

Minor "conflict" due to adjacent line changes in imports (because 7a50fe8 is not in the 20.10 branch)

This takes the same approach as was implemented on docker build, where a warning
is printed if FROM --platform=... is used (added in 3996953)

Before:

docker rmi armhf/busybox
docker pull --platform=linux/s390x armhf/busybox

Using default tag: latest
latest: Pulling from armhf/busybox
d34a655120f5: Pull complete
Digest: sha256:8e51389cdda2158935f2b231cd158790c33ae13288c3106909324b061d24d6d1
Status: Downloaded newer image for armhf/busybox:latest
docker.io/armhf/busybox:latest

With this change:

docker rmi armhf/busybox
docker pull --platform=linux/s390x armhf/busybox

Using default tag: latest
latest: Pulling from armhf/busybox
d34a655120f5: Pull complete
Digest: sha256:8e51389cdda2158935f2b231cd158790c33ae13288c3106909324b061d24d6d1
Status: Downloaded newer image for armhf/busybox:latest
WARNING: image with reference armhf/busybox was found but does not match the specified platform: wanted linux/s390x, actual: linux/arm64
docker.io/armhf/busybox:latest

And daemon logs print:

WARN[2021-04-26T11:19:37.153572667Z] ignoring platform mismatch on single-arch image error="image with reference armhf/busybox was found but does not match the specified platform: wanted linux/s390x, actual: linux/arm64" image=armhf/busybox

When pulling without specifying `--platform, no warning is currently printed (but we can add a warning in future);

docker rmi armhf/busybox
docker pull armhf/busybox

Using default tag: latest
latest: Pulling from armhf/busybox
d34a655120f5: Pull complete
Digest: sha256:8e51389cdda2158935f2b231cd158790c33ae13288c3106909324b061d24d6d1
Status: Downloaded newer image for armhf/busybox:latest
docker.io/armhf/busybox:latest

Signed-off-by: Sebastiaan van Stijn [email protected]
(cherry picked from commit 424c0eb)
Signed-off-by: Sebastiaan van Stijn [email protected]

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

…form

This takes the same approach as was implemented on `docker build`, where a warning
is printed if `FROM --platform=...` is used (added in 3996953)

Before:

    docker rmi armhf/busybox
    docker pull --platform=linux/s390x armhf/busybox

    Using default tag: latest
    latest: Pulling from armhf/busybox
    d34a655120f5: Pull complete
    Digest: sha256:8e51389cdda2158935f2b231cd158790c33ae13288c3106909324b061d24d6d1
    Status: Downloaded newer image for armhf/busybox:latest
    docker.io/armhf/busybox:latest

With this change:

    docker rmi armhf/busybox
    docker pull --platform=linux/s390x armhf/busybox

    Using default tag: latest
    latest: Pulling from armhf/busybox
    d34a655120f5: Pull complete
    Digest: sha256:8e51389cdda2158935f2b231cd158790c33ae13288c3106909324b061d24d6d1
    Status: Downloaded newer image for armhf/busybox:latest
    WARNING: image with reference armhf/busybox was found but does not match the specified platform: wanted linux/s390x, actual: linux/arm64
    docker.io/armhf/busybox:latest

And daemon logs print:

   WARN[2021-04-26T11:19:37.153572667Z] ignoring platform mismatch on single-arch image  error="image with reference armhf/busybox was found but does not match the specified platform: wanted linux/s390x, actual: linux/arm64" image=armhf/busybox

When pulling without specifying `--platform, no warning is currently printed (but we can add a warning in future);

    docker rmi armhf/busybox
    docker pull armhf/busybox

    Using default tag: latest
    latest: Pulling from armhf/busybox
    d34a655120f5: Pull complete
    Digest: sha256:8e51389cdda2158935f2b231cd158790c33ae13288c3106909324b061d24d6d1
    Status: Downloaded newer image for armhf/busybox:latest
    docker.io/armhf/busybox:latest

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit 424c0eb)
Signed-off-by: Sebastiaan van Stijn <[email protected]>

@cpuguy83 cpuguy83 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah

Copy link
Copy Markdown
Member Author

@tianon @samuelkarp ptal

@rvolosatovs rvolosatovs left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tonistiigi tonistiigi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. If possible we should look into how to avoid double warning on default docker run that does implicit pull.

@thaJeztah
thaJeztah merged commit cc5a381 into moby:20.10 Jul 15, 2021
@thaJeztah
thaJeztah deleted the 20.10_backport_warn_on_non_matching_platform branch July 15, 2021 18:46
@ppp0

ppp0 commented Sep 1, 2022

Copy link
Copy Markdown

Is this actually working? I don't get any warnings on Docker 20.10.17 for e.g.

docker pull --platform=linux/s390x metabase/metabase:v0.44.1

which surely is not meant to run on arch linux/s390x

@thaJeztah

Copy link
Copy Markdown
Member Author

@ppp0 Thanks for asking (and for the example).

Hmm... so, it works...

docker pull --platform=linux/s390x arm32v6/bash
...
WARNING: image with reference arm32v6/bash was found but does not match the specified platform: wanted linux/s390x, actual: linux/arm/v6
docker.io/arm32v6/bash:latest

..but I suspect your example may be hitting another (sigh) backward-compatibility condition (will have to check). What I suspect could be the case;

  • old images did not have platform (os/arch) information
  • if no platform information is present, it's considered linux/amd64 (as it was the only platform originally supported)
  • for these single-arch images, linux/amd64 and "empty" to be considered equal (<-- to be checked if I'm right there)

I know we had some stricter checks at some point, but there were many (single-arch) images built using cross-compilation tools; for those images, the image metadata did not match the image's actual architecture. If those images are part of a multi-arch image (manifest index), then the manifest index would contain the "correct" os/arch, but when pulled directly (not as part of a multi-arch image), such images would be rejected, causing quite some issues, so validation was relaxed for those.

So, I think a combination of the above is happening, causing the warning to not be printed. Note that this warning is a bit of a "best effort" attempt to make these cases visible, because of the aforementioned relaxation of the validation when we had to implement. That said; it would definitely be good (if possible) to also print a warning for these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants