我正在为我的 go 项目构建一个多阶段的 Dockerfile。
FROM golang:latest as builder
COPY ./go.mod /app/go.mod
COPY ./go.sum /app/go.sum
#exporting go1.11 module support variable
ENV GO111MODULE=on
WORKDIR /app/
#create vendor directory
RUN go mod download
COPY . /app/
RUN go mod vendor
#building source code
RUN go build -mod=vendor -o main -v ./src/
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /app/main /app/main
WORKDIR /app/
ARG port="80"
ENV PORT=$port
EXPOSE $PORT
CMD ["./main"]
当我运行图像时,它会引发错误:
standard_init_linux.go:207: exec user process caused "no such file or directory"
我已经验证了“主”文件存在于 /app/main 中。我还尝试通过添加来授予可执行权限
chmod +x /app/main
但它仍然不起作用。什么可能是错的?