standard_init_linux.go:190:exec用户进程引起“ exec格式错误”。运行Go二进制文件时 [英] standard_init_linux.go:190: exec user process caused "exec format error" when running Go binary

查看:1653
本文介绍了standard_init_linux.go:190:exec用户进程引起“ exec格式错误”。运行Go二进制文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am attempting to create a container with my Go binary in for use as a database migrator. If I run the binary it works perfectly, however, I am struggling to put it into a container and run it in my docker-compose stack.

下面是我的Dockerfile。

Below is my 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数据库已正确设置,但我在数据库迁移器容器的日志中收到此错误。

When I run my docker-compose stack the MySQL database gets setup correctly but I receive this error in the logs for my database migrator container.


data- migrator_1 | standard_init_linux.go:190:exec用户进程导致 exec格式错误

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


推荐答案

相同的错误消息。对我而言,解决方法是为正确的体系结构交叉构建。就我而言,是amd64。像这样:

I had the same error message. For me the fix was to cross build the for the right architecture. In my case amd64. Like this:

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

这篇关于standard_init_linux.go:190:exec用户进程引起“ exec格式错误”。运行Go二进制文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆