Scene
In the process of packaging the golang application into a docker image, execute the following command
docker run -it -P --name docker_client -m 1024m --net host docker_client:1.0
After execution, the server reported this error
standard_init_linux.go:190: exec user process caused "exec format error"
It’s useless to follow the online method. I can run normally on the virtual machine. I’ll look at my dockerfile carefully later
FROM golang:alpine
ENV GO111MODULE=on \
GOPROXY=https://goproxy.cn,direct \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
# Create an apps directory in the container root directory
WORKDIR /build
# Copy the go_docker_demo1 executable from the current directory
COPY . .
# Compile our code into a binary executable app
RUN go build -o app .
# Move to the /dist directory where the generated binaries are stored
WORKDIR /dist
# Copy the binaries from the /build directory to here
RUN cp /build/app .
# Expose the port
EXPOSE 8080
# The command to run the golang program
CMD ["/dist/app"]
It is found that the goarch parameter is AMD64. Check the relevant version of the server later
docker version
#check the version of the docker
A problem was found in the output information. One line of parameters is arm64
OS/Arch: linux/arm64
So I modified the dockerfile file
FROM golang:alpine
ENV GO111MODULE=on \
GOPROXY=https://goproxy.cn,direct \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=arm64
# Create an apps directory in the container root directory
WORKDIR /build
# Copy the go_docker_demo1 executable from the current directory
COPY . .
# Compile our code into a binary executable app
RUN go build -o app .
# Move to the /dist directory where the generated binaries are stored
WORKDIR /dist
# Copy the binaries from the /build directory to here
RUN cp /build/app .
# Expose the port
EXPOSE 8080
# The command to run the golang program
CMD ["/dist/app"]
After rebuilding the dockerfile image, it will run normally.