Skip to content

Docker build fails on Apple Silicon due to CGO + amd64 mismatch (gcc -m64 error) #1

@Tibinsunny

Description

@Tibinsunny

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

  1. Build the Docker image on an Apple Silicon machine (arm64)
  2. Use the current Dockerfile/backend build stage
  3. 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
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions