2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

M2 Macbook で platform linux/amd64 を指定して golang 1.20 でビルドすると segmentation faultが発生

Last updated at Posted at 2023-07-06

環境

  • Apple M2 13.4.1(22F82)
  • Rancher Desktop Version: 1.8.1
  • golang 1.20 (Dockerfile)

問題内容

以下のような Dockerfile を --platform linux/amd64 のオプションを付与してビルドするときに segmentation fault が発生した。

docker build ./ -t samle:latest --platform linux/amd64
Dockerfile
FROM golang:1.20 AS builder

WORKDIR /build
COPY . ./
RUN go mod download
RUN go build -trimpath -ldflags '-w -s' -o ./main

ENTRYPOINT ["/build/main"]

エラー内容

# runtime/cgo: gcc: signal: segmentation fault (core dumped)                   

解決策

CGO_ENABLED=0 を環境変数に設定することで発生しなくなり解決。

Dockerfile
FROM golang:1.20 AS builder

ENV CGO_ENABLED=0

WORKDIR /build
COPY . ./
RUN go mod download
RUN go build -trimpath -ldflags '-w -s' -o ./main

ENTRYPOINT ["/build/main"]
2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?