Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for usage of --platform= flag in Dockerfile FROM (FromPlatformFlagConstDisallowed) #5131

Closed
thompson-shaun opened this issue Jul 8, 2024 · 1 comment · Fixed by #5140

Comments

@thompson-shaun
Copy link
Collaborator

thompson-shaun commented Jul 8, 2024

Specifying --platform= with a constant value in the Dockerfile FROM instruction forces the Image to build only one target platform. This has some drawbacks:

  • Make it no longer possible to build a multi-platform Image from this Dockerfile.
  • The platform that you build on must be the same as the platform specified in --platform=

The recommended approach include:

  • Omit FROM --platform in the docker file and to specify in buildx --platform= during the build if control of the image platform target is needed.
  • Use the $BUILDPLATFORM or other combination of variables for --platform in a FROM
    stage name should include a valid OS or ARCH
  • --platform flag should not be used with a constant value, unless stage name also contains os or arch

Reference

  • BUILDPLATFORM — matches the current machine. (e.g. linux/amd64)
  • BUILDOS — os component of BUILDPLATFORM, e.g. linux
  • BUILDARCH — e.g. amd64, arm64, riscv64
@thompson-shaun thompson-shaun added this to the v0.15.0 milestone Jul 8, 2024
@tonistiigi tonistiigi changed the title Add check for usage of --platfomr= flag in Dockerfile FROM (FromPlatformFlagConstDisallowed) Add check for usage of --platform= flag in Dockerfile FROM (FromPlatformFlagConstDisallowed) Jul 8, 2024
@thompson-shaun thompson-shaun assigned jsternberg and unassigned daghack Jul 9, 2024
@SampsonCrowley
Copy link

how can we silence this warning?

Make it no longer possible to build a multi-platform Image from this Dockerfile.

Not everyone wants a multi-platform image. some things only ever are ran from one platform no matter where it's built from

The platform that you build on must be the same as the platform specified in --platform=

I don't think that's true. I've built AMD64-only images from arm OSX without an issue

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

Successfully merging a pull request may close this issue.

5 participants