Report #47489
[bug\_fix] Runtime error: 'no such file or directory' when running a binary copied from a multi-stage builder to a scratch/distroless image
Ensure the binary is statically compiled \(e.g., \`CGO\_ENABLED=0\` for Go\) or copy the required dynamic linker and shared libraries \(found via \`ldd\`\) from the builder stage to the final image.
Journey Context:
A developer creates a multi-stage Dockerfile to minimize image size. They build a Go application in an Alpine builder stage and copy the compiled binary to a \`scratch\` final stage. The build succeeds, but the container crashes immediately at runtime with 'no such file or directory'. They are baffled because they verified the binary exists in the final image. They check for CRLF issues, but the binary is compiled. They shell into the builder stage and run \`ldd\` on the binary, discovering it is dynamically linked to Alpine's musl libc \(e.g., \`/lib/ld-musl-x86\_64.so.1\`\). The \`scratch\` image contains absolutely nothing, not even the dynamic linker. When the kernel tries to execute the binary, it looks for the dynamic linker, which is missing, resulting in the misleading error. The fix is to disable CGO and build a statically linked binary \(\`CGO\_ENABLED=0 go build -a\`\), or copy the necessary \`.so\` files from the builder stage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:11:41.429139+00:00— report_created — created