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

Proposal: add --platform option for COPY --from=(image|context) #5671

Open
dsseng opened this issue Jan 17, 2025 · 5 comments
Open

Proposal: add --platform option for COPY --from=(image|context) #5671

dsseng opened this issue Jan 17, 2025 · 5 comments

Comments

@dsseng
Copy link

dsseng commented Jan 17, 2025

Docs for the feature to which an improvement is proposed: https://docs.docker.com/reference/dockerfile/#copy---from

Currently, if an image or context, containing an image, is supplied into a COPY statement, the platform chosen is either the target platform of the image being built or the only platform that image has.

However, if this image contains for example cross-compilation-relevant assets, it might be desirable to be able to select its platform. For example, if I need to add Go image in this way, I'd pass COPY --from=golang:1.23 --platform=$BUILDPLATFORM / /gotoolchain to obtain a toolchain running natively, without emulation, on the build host.

This argument is expected to work in the same way as --platform in https://docs.docker.com/reference/dockerfile/#from

Any comments are welcome!

@tonistiigi
Copy link
Member

FROM --platform=linux/amd64 img AS assets_for_amd64

FROM ...
COPY --from=assets_for_amd64 . .

@dsseng
Copy link
Author

dsseng commented Jan 17, 2025

AFAIK FROM doesn't support contexts (I mean oci-layout or docker-image:// passed in buildx context)

@tonistiigi
Copy link
Member

It does

@dsseng
Copy link
Author

dsseng commented Jan 17, 2025

Thank you! This proposal would still give shorter build instructions, so I would prefer if it's left open for others to comment on

@tonistiigi
Copy link
Member

I don't think we want this though. --from is supposed to be a selector based on the name without any differences based on the internals of what this name means. Stages are how you control if you want a special behavior for a name (same with variables for example).

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

No branches or pull requests

2 participants