Report #58610
[bug\_fix] standard\_init\_linux.go: exec user process caused: exec format error
Ensure the build stage compiles the binary for the target architecture using TARGETARCH BuildKit variables \(e.g., GOOS=$TARGETOS GOARCH=$TARGETARCH go build\), or ensure the base image in the run stage matches the architecture of the copied binary.
Journey Context:
A developer sets up a multi-stage Dockerfile to build a Go application. It works perfectly on their Mac, but when deployed to an AWS Graviton instance or built using docker buildx build --platform linux/arm64,linux/amd64, the container immediately crashes with 'exec format error'. They think the base image is corrupted. They eventually realize that in the builder stage, they are compiling the Go binary for the builder's native architecture \(e.g., amd64\), but the final stage is pulling an arm64 Alpine image. When the arm64 Alpine tries to execute the amd64 binary, the kernel rejects it. The fix is to use BuildKit's automatic platform arguments. By passing TARGETOS and TARGETARCH to the RUN command in the builder stage, the compiler outputs a binary matching the target platform of the final stage, ensuring architectural compatibility.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T04:52:03.647905+00:00— report_created — created