standard_init_linux.go:190: exec 用户进程在运行 Go 二进制文件时导致“exec 格式错误”
时间:2023-04-09
浏览:133
作者:佚名
今天golang学习网给大家带来了《standard_init_linux.go:190: exec 用户进程在运行 Go 二进制文件时导致“exec 格式错误”》,其中涉及到的知识点包括golang等等,无论你是小白还是老手,都适合看一看哦~有好的建议也欢迎大家在评论留言,若是看完有所收获,也希望大家能多多点赞支持呀!一起加油学习~
问题内容
我正在尝试使用我的 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 数据库会正确设置,但我在数据库迁移器容器的日志中收到此错误。
数据迁移器_1 | standard_init_linux.go:190: exec 用户进程导致“exec 格式错误”
正确答案
我有同样的错误信息。对我来说,解决方法是交叉构建正确的架构。在我的情况下,amd64。像这样:
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o [OUTPUT] .
今天带大家了解了golang的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.28
11.28
11.28
11.28
11.28
11.28
热门专题
