【发布时间】: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