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

标签 docker go

我正在尝试使用我的 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/

相关文章:

java - Dockerized SpringBoot REST api 不支持请求方法 'GET'

Docker 文件和撰写更新

php - 如何使用php docker容器查看php日志信息?

go - 我可以检查上下文是否已经设置了超时吗?

json - Golang 中的语法错误

ubuntu - Dockerfile 连接到 ODBC(例如 HPE Vertica)设置

mongodb - 过滤集合但按内部属性排序

go - 初始化嵌套匿名结构

windows - 由于未知原因,无法在 Windows 上的 Docker 环境下运行 Nginx

docker - 如何使用 docker-compose 配置网络