standard_init_linux.go:190:运行Go二进制文件时,exec用户进程导致“ exec格式错误”

时间:2019-04-21 21:26:40

标签: 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用户进程导致“ exec格式错误”

2 个答案:

答案 0 :(得分:1)

检查是否类似于containers/buildah issue 475

  

我认为是因为系统不知道如何执行文件。
  仅供参考:What's the appropriate Go shebang line?

     

还要注意Dockerfile中CMD / ENTRYPOINT的shell form and exec form之间的区别。

     

只需将#!/bin/bash添加到我的入口点文件中即可解决此问题。

或者:

  

原来#!/bin/bash在我的入口点文件中,但是由于我复制并粘贴到该文件中,因此第一行是换行符,而不是#!/bin/bash,实际上忽略了它。 br />   如果这样做对所有人也有帮助:删除空行,一切正常。

或者:

  

万一有人发现它有用,如果您的Shell脚本使用CRLF作为行尾和/或使用BOM的UTF-8(例如,如果您在Visual Studio中创建了Shell脚本文件),则会出现此问题。
  更改为仅LF,并且直接使用UTF-8修复了它。

或者(也许不是您的情况,但有待完善):

  

对于在应用此修复程序后出现standard_init_linux.go:190: exec user process caused "no such file or directory"错误的任何人,您可能都在不使用bash的高山基础图像上。

     

#!/bin/bash替换为#!/bin/sh就能解决问题!

答案 1 :(得分:0)

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

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o vtr-manual-ats-processes .
相关问题