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

[Question] understand of "--platform=$BUILDPLATFORM" in dockerfile #1241

Closed
chendave opened this issue Nov 1, 2019 · 3 comments
Closed

[Question] understand of "--platform=$BUILDPLATFORM" in dockerfile #1241

chendave opened this issue Nov 1, 2019 · 3 comments

Comments

@chendave
Copy link
Collaborator

chendave commented Nov 1, 2019

I am trying to understand the purpose of specify below instruction in dockerfile,

FROM --platform=$BUILDPLATFORM AS alpine

I saw some explanation from here moby/moby#32487

They can also be used for cross compilation. In this example build stage is fixed to worker architecture but for the exported stage, alpine for target architecture is used.

Is there any case the build stage is not fixed to work architecture without specifying the

FROM --platform=$BUILDPLATFORM

???

Is it possible for us to build like below irrespective of QEMU support on the build machine?

from --platform=$TARGETPLATFORM alpine
...

and for what's use-case?

Many thanks!

@tonistiigi
Copy link
Member

Is there any case the build stage is not fixed to work architecture without specifying the

Yes. In case you want to run binaries for your main architecture even if the user has requested an image for another architecture as a result of the build.

from --platform=$TARGETPLATFORM alpine is always the same as from alpine

from --platform=$BUILDPLATFORM alpine is only the same as from alpine if no --platform is specified for the build or if --platform value matches the native platform of the node.

Note that specifying build --platform does not mean that the build is guaranteed to return an image for that platform. The only thing it does is change the TARGETPLATFORM value that automatically has an effect on all the FROM commands that do not set --platform flag itself.

Eg. if you have a dockerfile:

from --platform=linux/arm64 alpine
copy foo .

building this dockerfile will always result in arm64 image, even if you build it with docker build --platform=linux/amd64, because it returns an image based on arm64 alpine. (Therefore the example is bad and you should never write a dockerfile like this). But if you use TARGETPLATFORM/default there then the matching alpine version is pulled and your resulting image will match the platform of build --platform value.

@chendave
Copy link
Collaborator Author

chendave commented Nov 7, 2019

Thanks for the clarification! @tonistiigi

@chendave chendave closed this as completed Nov 7, 2019
@alexellis
Copy link

Hi @tonistiigi @AkihiroSuda, do you know if it's possible to override the platform when using the Buildkit SDK as we do in OpenFaaS Cloud? https://github.com/openfaas/openfaas-cloud/blob/master/of-builder/main.go#L194

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

No branches or pull requests

3 participants