【问题标题】:Cannot start service app: OCI runtime create failed: container_linux.go:349无法启动服务应用程序:OCI 运行时创建失败:container_linux.go:349
【发布时间】:2020-10-27 04:41:41
【问题描述】:

当我尝试使用 docker 启动我的 go 应用程序时遇到了一些麻烦。 ERROR: for app Cannot start service app: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"./main\": permission denied": unknown 当我尝试做docker-compose up

这是我的 dockerfil:

# Dockerfile References: https://docs.docker.com/engine/reference/builder/

# Start from the latest golang base image
FROM golang:1.13 as builder

# Set the Current Working Directory inside the container
WORKDIR /memesbot

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download

# Copy the source from the current directory to the Working Directory inside the container
COPY . .

# Build the Go app
RUN go build -o /memesbot/cmd/main .

######## Start a new stage from scratch #######
FROM alpine:latest


RUN apk --no-cache add ca-certificates

WORKDIR /root/

# Copy the Pre-built binary file from the previous stage
COPY --from=builder /memesbot/cmd/main .

# Command to run the executable
CMD ["./main"]

还有 docker-compose.yml

version: '3'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "7777:7777"
    environment:
      TELEGRAM_TOKEN: xxxyyy

有人知道我该如何解决这个问题吗?

【问题讨论】:

    标签: docker go docker-compose dockerfile


    【解决方案1】:

    为你的可执行文件设置它应该工作的权限。

    RUN chmod +x ./main
    # Command to run the executable
    CMD ["./main"]
    

    【讨论】:

    • 只需在您的文件系统本地执行。
    • RUN 添加到文件中不起作用。我必须将chmod 直接应用于本地文件。让我知道是否有替代方案,因为这意味着我们必须为开发人员更新自述文件,因为这是一个问题,只有 Mac 没有权限,而在 Windows 上没有问题
    • 以上内容适用于多阶段构建,如果您从主机消费然后如上所述设置主机权限,但如果您使用挂载可能就是这种情况?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-20
    • 2021-06-08
    • 2020-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多