Running a docker Image of Golang failed, with error 'starting container process caused: exec: "/path": permission denied'

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

Running a docker Image of Golang failed, with error 'starting container process caused: exec: "/path": permission denied'

问题

我成功地从 Dockerfile 构建了一个 Go Docker 镜像,但是当我运行 docker run -p 端口:端口 --name 镜像名称 镜像ID 时,出现了 "permission denied" 错误。

这是我的 Dockerfile:

FROM golang:1.17.2-alpine3.13 as build

WORKDIR /app

COPY . .

RUN go build -o app

FROM alpine:3.7

COPY --from=build /app /usr/local/bin/go_webhooks

RUN chmod +x /usr/local/bin/go_webhooks

ENTRYPOINT ["/usr/local/bin/go_webhooks"]

我尝试使用 chmod,但仍然无法解决问题。

实际的错误消息是:

docker run -p 8000:8000 --name go_webs3 d5f30e8f9703 
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:380: starting container process caused: exec:
"/usr/local/bin/go_webhooks": permission denied: unknown. 
ERRO[0000] error waiting for container: context canceled
英文:

I build a Go docker image from docker file successfully, but docker run -p port:port --name imagename imageid gives me permission denied error.

This is my docker file

FROM golang:1.17.2-alpine3.13 as build

WORKDIR /app

COPY . .

RUN go build -o app

FROM alpine:3.7

COPY --from=build /app /usr/local/bin/go_webhooks

RUN chmod +x /usr/local/bin/go_webhooks

ENTRYPOINT ["/usr/local/bin/go_webhooks"]

I tried using chmod but still could not solve it.

The actual error message is:

docker run -p 8000:8000 --name go_webs3 d5f30e8f9703 
docker: Error response from daemon: OCI runtime create failed:
container_linux.go:380: starting container process caused: exec:
"/usr/local/bin/go_webhooks": permission denied: unknown. 
ERRO[0000] error waiting for container: context canceled

答案1

得分: 1

过去的类似错误信息指出了一个go build的问题。

但在你的情况下,将一个文件夹复制到/usr/local/bin/go_webhooks会使go_webhooks成为一个文件夹

WORKDIR /app
# 表示/app是一个文件夹

你不能直接执行一个文件夹。
你的入口点需要引用该文件夹内的可执行文件。

你可能需要将构建的文件复制到/app内:

COPY --from=build /app/app /usr/local/bin/go_webhooks
英文:

A past similar error message pointed out to a go build issue.

But in your case, copying a folder to /usr/local/bin/go_webhooks would make go_webhooks a folder.

WORKDIR /app
# means /app is a folder

You cannot directly execute a folder.
Your Entrypoint needs to reference an executable inside that folder.

You might needs to copy the built file inside /app:

COPY --from=build /app/app /usr/local/bin/go_webhooks

huangapple
  • 本文由 发表于 2021年11月2日 13:53:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/69805920.html
匿名

发表评论

匿名网友

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

确定