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 |
Beta Was this translation helpful? Give feedback.
-
I'm trying to craft a
Dockerfile
to 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.proto
files to.h
files (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 build
to honor the--platform=$BUILDPLATFORM
for theproto-build
target. I added aRUN
line 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/amd64
The real problems start when I try to use
bake
and multiple output platforms;bake
ends up building theproto-build
target twice, once for each platform.As I understand it, the
--platform
argument only changes the$TARGETPLATFORM
argument to the Dockerfile, not the$BUILDPLATFORM
. So, questions:Beta Was this translation helpful? Give feedback.
All reactions