无法启动服务应用程序:OCI 运行时创建失败:container_linux.go:349

god*_*lpr 5 go docker dockerfile docker-compose

当我尝试使用 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

这是我的 mulristage 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"]

Run Code Online (Sandbox Code Playgroud)

和 docker-compose.yml

# 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"]

Run Code Online (Sandbox Code Playgroud)

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

Adi*_*iii 10

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

RUN chmod +x ./main
# Command to run the executable
CMD ["./main"]
Run Code Online (Sandbox Code Playgroud)

  • 只需在文件系统上本地执行即可。 (2认同)