Repository navigation
Cross-platform buildx and proper use of $BUILDPLATFORM #1893
Replies: 1 comment
|
The effort of simplifying my Dockerfile for this post helped me explore the problem, and I discovered that if I break the common dependency on the So why is this? I'd like to have all the dev tools containerized on either host architecture, so I can build the whole stack from either architecture. (Further down in my real Dockerfile, there's also a vscode devcontainer built on top of this, and I can run it on my arm host.) But having a shared ancestor image in the same Dockerfile seems to cause it to ignore the $BUILDPLATFORM. Curiously, I can still have both |
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to craft a
Dockerfileto build a cross-platform (amd64 and arm64) application withbuildx build. Some precursors are platform-independent and only need to be done once, e.g., compiling.protofiles to.hfiles (or whatever). But for my output binary, it's easier/better to use qemu and just emulate a native compiler environment.I reduced my problem to the simplest possible Dockerfile I could, and I'm having difficulty getting
buildx buildto honor the--platform=$BUILDPLATFORMfor theproto-buildtarget. I added aRUNline that fails if it's not using my host architecture:I'm then invoking:
docker buildx build --platform linux/arm64 --target=runtime .As noted, this tries to build the protobufs under arm instead of using the
$BUILDPLATFORM, so it outputs:Host: aarch64; BUILDPLATFORM: linux/amd64The real problems start when I try to use
bakeand multiple output platforms;bakeends up building theproto-buildtarget twice, once for each platform.As I understand it, the
--platformargument only changes the$TARGETPLATFORMargument to the Dockerfile, not the$BUILDPLATFORM. So, questions:All reactions