Golang Dockerfile 权限被拒绝

huangapple go评论97阅读模式
英文:

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 [&quot;/my-app&quot;]

and here is my docker-compose

<!-- language: lang-yaml -->

version: &quot;3.7&quot;

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

huangapple
  • 本文由 发表于 2022年7月20日 08:47:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/73044866.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定