gpt4 book ai didi

docker - standard_init_linux.go :190: exec user process caused "exec format error" when running Go binary

转载 作者:IT王子 更新时间:2023-10-29 01:11:50 32 4
gpt4 key购买 nike

我正在尝试使用我的 Go 二进制文件创建一个容器,用作数据库迁移器。如果我运行二进制文件,它会完美运行,但是,我很难将它放入容器中并在我的 docker-compose 堆栈中运行它。

下面是我的 Dockerfile。

FROM golang:1.11 AS build_base

WORKDIR /app

ENV GO111MODULE=on
# We want to populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .
RUN go mod download

FROM build_base AS binary_builder
# Here we copy the rest of the source code
COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build

#In this last stage, we start from a fresh Alpine image, to reduce the image size and not ship the Go compiler in our production artifacts.
FROM alpine AS database-migrator
# We add the certificates to be able to verify remote instances
RUN apk add ca-certificates
COPY --from=binary_builder /app /app

ENTRYPOINT ["/app/binary-name"]

当我运行我的 docker-compose 堆栈时,MySQL 数据库得到正确设置,但我在我的数据库迁移器容器的日志中收到此错误。

data-migrator_1 | standard_init_linux.go:190: exec user process caused "exec format error"

最佳答案

我有同样的错误信息。对我来说,解决方法是交叉构建正确的架构。在我的例子中是 amd64。像这样:

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o [OUTPUT] .

关于docker - standard_init_linux.go :190: exec user process caused "exec format error" when running Go binary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55786898/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com