【问题标题】:Dockerfile: Error response from daemon: OCI runtime create failed: container_linux.go:349Dockerfile:来自守护程序的错误响应:OCI 运行时创建失败:container_linux.go:349
【发布时间】:2021-02-20 13:38:30
【问题描述】:

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

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

这个项目的目录如下:

./
├── cmd
│   └── webserver
│       └── main.go
├── Dockerfile
├── go.mod
└── server.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 中。

【问题讨论】:

  • 尝试使用 sudo 运行

标签: docker go dockerfile go-modules


【解决方案1】:

我实际上是通过修改 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"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-28
    • 1970-01-01
    • 2019-04-30
    • 2020-01-11
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 2020-04-19
    相关资源
    最近更新 更多