尝试运行包含golang应用程序的docker映像时遇到一些问题。
这是错误:enter code here
standard_init_linux.go:211:exec用户进程导致“ exec格式错误”
这是我的环境:
GOARCH="amd64"
GOBIN="/home/nikolaj//home/nikolaj/go/bin"
GOCACHE="/home/nikolaj/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/nikolaj/go"
GOPROXY=""
GORACE=""
GOROOT="/snap/go/4765"
GOTMPDIR=""
GOTOOLDIR="/snap/go/4765/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build908015468=/tmp/go-build -gno-record-gcc-switches"
go environment : GOARCH="amd64"
GOBIN="/home/nikolaj//home/nikolaj/go/bin"
GOCACHE="/home/nikolaj/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/nikolaj/go"
GOPROXY=""
GORACE=""
GOROOT="/snap/go/4765"
GOTMPDIR=""
GOTOOLDIR="/snap/go/4765/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build838573681=/tmp/go-build -gno-record-gcc-switches"
dockerfile:
FROM golang:1.12.0
WORKDIR /app
ENV SRC_DIR=/go/src/vk_acceptor/
ADD . $SRC_DIR
RUN cd $SRC_DIR; env; goenv; export GO111MODULE=on; go get -u; go build -o application; cp application /app/
RUN chmod +x application
ENTRYPOINT ["./application"]
格式化RUN command
后,它看起来像这样:RUN cd $SRC_DIR && env && goenv && export GO111MODULE=on && go get -u && go build -o application && cp application /app/
docker build .
命令的输出:
Sending build context to Docker daemon 9.067MB
Step 1/7 : FROM golang:1.12.0
---> cee68f119e19
Step 2/7 : WORKDIR /app
---> Using cache
---> 5bffbbf8f161
Step 3/7 : ENV SRC_DIR=/go/src/vk_acceptor/
---> Using cache
---> bf145f38f8db
Step 4/7 : ADD . $SRC_DIR
---> 766466f20647
Step 5/7 : RUN cd $SRC_DIR && env && goenv && export GO111MODULE=on && go get -u && go build -o application && cp application /app/
---> Running in 7aeb8905c137
HOSTNAME=7aeb8905c137
SRC_DIR=/go/src/vk_acceptor/
HOME=/root
OLDPWD=/app
PATH=/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
GOPATH=/go
PWD=/go/src/vk_acceptor
GOLANG_VERSION=1.12
/bin/sh: 1: goenv: not found
The command '/bin/sh -c cd $SRC_DIR && env && goenv && export GO111MODULE=on && go get -u && go build -o application && cp application /app/' returned a non-zero code: 127
答案 0 :(得分:0)
如果查看输出错误,则可以清楚地看到错误消息:
/bin/sh: 1: goenv: not found
我想您想在命令中键入go env
?
答案 1 :(得分:0)
standard_init_linux.go:211: exec user process caused "exec format error"
错误的发生有多种原因,不仅如许多论坛所说的那样,不仅是当您尝试使用不同于主机的体系结构启动映像时。
就我而言,发生此错误是由于捆绑程序放置在Docker容器中的错误目录中。