Description
Docker build fails when building the backend with CGO enabled on Apple Silicon machines.Tested on M4
The failure occurs during go build with the following error:
gcc: error: unrecognized command-line option '-m64'
Steps to Reproduce
- Build the Docker image on an Apple Silicon machine (arm64)
- Use the current Dockerfile/backend build stage
- Build reaches the Go compile step with CGO enabled
Build Command Used
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o <binary> main.go
Error Output
# runtime/cgo
gcc: error: unrecognized command-line option '-m64'
Root Cause (Analysis)
- Alpine pulls an
arm64 base image on Apple Silicon by default
GOARCH=amd64 forces Go to target amd64
gcc inside the container is arm64
- This causes CGO to pass
-m64, which arm64 gcc does not support
