Dockerfile:来自守护进程的错误响应:OCI运行时创建失败:container_linux.go:349



我下面的目录结构基于:https://github.com/golang-standards/project-layout

我已经创建了一个非常简单的应用程序,基本上我想将其容器化。基本上我在那里有两个文件。server.go是http端点的定义,主文件在cmd/webserver下启动名为main.go的服务器。

这个项目的目录看起来像:

./
├── cmd
│   └── webserver
│       └── main.go
├── Dockerfile
├── go.mod
└── server.go

go.mod

module github.com/geborskimateusz/auth
go 1.15

Dockerfile看起来像这个

FROM golang:alpine
# Set necessary environmet variables needed for our image
ENV GO111MODULE=on 
CGO_ENABLED=0 
GOOS=linux 
GOARCH=amd64
# Move to working directory /build
WORKDIR /build
# Copy and download dependency using go mod
COPY go.mod .
RUN go mod download
# Copy the code into the container
COPY . .
# Build the application
RUN go build -o main .
# Move to /dist directory as the place for resulting binary folder
WORKDIR /dist
# Copy binary from build to main folder
RUN cp /build/main .
# Export necessary port
EXPOSE 3000
# Command to run when starting the container
CMD ["/dist/main"]:

构建是成功的,但问题是当我运行docker run-p 3000:3000 geborskimateusz/auth我得到了:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: "/dist/main": permission denied": unknown.
ERRO[0000] error waiting for container: context canceled 

我错过了什么?我想我可能需要在Dockerfile中cd到放置main.go(可执行文件(的cmd/webserver中。

我实际上通过将DockerFile修改为来解决了这个问题

FROM golang:alpine
WORKDIR /app
COPY go.mod .
RUN go mod download
COPY . .
RUN cd ./cmd/webserver/ && go build -o main . && cp main ../../ && cd ../../
CMD ["./main"]

相关内容

最新更新