简体   繁体   中英

Problem with run docker container contains golang project

I experience some problem when attempt to run a my docker image that contain golang application. This Is an error: enter code here standard_init_linux.go:211: exec user process caused "exec format error"

This Is my 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-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"

The 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"]

After formatting RUN command it looks like this: RUN cd $SRC_DIR && env && goenv && export GO111MODULE=on && go get -u && go build -o application && cp application /app/

Output of docker build . command :

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

If you look at the output error, you can clearly see the error message:

/bin/sh: 1: goenv: not found

I presume you wanted to type go env in your command?

The standard_init_linux.go:211: exec user process caused "exec format error" error occurs for various reasons, and not only when you try to launch an image with an architecture different from your host machine, as many forums say. In my case, this error occurred due to the fact that the bundled program was placed in the wrong directory in the docker container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM