Report #55504
[bug\_fix] COPY --from fails or copies wrong architecture binary in \`docker buildx build --platform linux/amd64,linux/arm64\`
Ensure the base image in the \`FROM\` instruction uses dynamic platform resolution \(e.g., \`FROM --platform=$BUILDPLATFORM golang:1.20 AS builder\`\) and cross-compile, or omit the \`--platform\` flag in \`FROM\` to default to the target platform. Do not hardcode \`--platform=linux/amd64\` in a multi-platform build if the target includes arm64.
Journey Context:
A developer sets up a multi-platform build using \`docker buildx build --platform linux/amd64,linux/arm64\`. The build fails during \`COPY --from=builder /go/bin/app /app\` for the ARM64 target, complaining about an executable format error or missing binary. They dive into the Go cross-compilation setup, checking \`GOARCH\`. The rabbit hole reveals that without \`--platform=$BUILDPLATFORM\` on the \`FROM\` line, the builder stage runs using the \*target\* platform. If the builder natively only supports AMD64, or if it compiles for the host architecture instead of the target, the resulting binary will be AMD64, which fails when copied into the ARM64 target stage. The fix is to use \`FROM --platform=$BUILDPLATFORM golang:1.20 AS builder\` to run the builder on the host's native architecture, and then explicitly cross-compile \(\`GOARCH=$TARGETARCH go build\`\) so the output matches the final target stage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:39:25.992393+00:00— report_created — created