英文:
Golang Dockerfile permission denied
问题
似乎在我的 Dockerfile 中存在权限分配错误,我无法解决它。
以下是错误信息:
Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/my-app": permission denied: unknown
这是我的 Dockerfile:
# syntax=docker/dockerfile:1
##
## Build
##
FROM golang:1.19rc2-buster AS build
WORKDIR /app
COPY src/go.mod ./
COPY src/go.sum ./
RUN go mod download
COPY src/*.go ./
RUN go build -o /my-app
##
## Deploy
##
FROM gcr.io/distroless/base-debian10
WORKDIR /
COPY --from=build /my-app /my-app
USER nonroot:nonroot
ENTRYPOINT ["/my-app"]
这是我的 docker-compose 文件:
version: "3.7"
services:
golang:
container_name: golang
build:
dockerfile: go.Dockerfile
ports:
- 8080:80
depends_on:
- cassandra
restart: always
cassandra:
container_name: cassandra
image: cassandra:latest
restart: always
ports:
- 9042:9042
希望这能帮到你。
英文:
I it seems like there is an error in the permission distribution on my Dockerfile and i can't seem to resolve it.
here is the error
Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/my-app": permission denied: unknown
Here is my Dockerfile
<!-- language: lang-sh -->
# syntax=docker/dockerfile:1
##
## Build
##
FROM golang:1.19rc2-buster AS build
WORKDIR /app
COPY src/go.mod ./
COPY src/go.sum ./
RUN go mod download
COPY src/*.go ./
RUN go build -o /my-app
##
## Deploy
##
FROM gcr.io/distroless/base-debian10
WORKDIR /
COPY --from=build /my-app /my-app
USER nonroot:nonroot
ENTRYPOINT ["/my-app"]
and here is my docker-compose
<!-- language: lang-yaml -->
version: "3.7"
services:
golang:
container_name: golang
build:
dockerfile: go.Dockerfile
ports:
- 8080:80
depends_on:
- cassandra
restart: always
cassandra:
container_name: cassandra
image: cassandra:latest
restart: always
ports:
- 9042:9042
答案1
得分: 1
请确保你的Go代码包含以下内容:
package main
这是Go语言中的包声明,它指定了当前文件所属的包名为"main"。
英文:
Just make sure that your go code contain a
package main
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论