4

I have some troubles when I try to start my go application with docker. ERROR: for app Cannot start service app: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"./main\": permission denied": unknown It happenes when I try to do docker-compose up

It is my 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"]

And docker-compose.yml

version: '3'

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

Does somebody know how can I fix this?

Pang
  • 9,564
  • 146
  • 81
  • 122
godvlpr
  • 141
  • 1
  • 3
  • 11

1 Answers1

10

Set the permission to your executable it should work.

RUN chmod +x ./main
# Command to run the executable
CMD ["./main"]
Adiii
  • 54,482
  • 7
  • 145
  • 148
  • 2
    Just do it locally on your filesystem. – jmoz Oct 12 '20 at 06:19
  • Adding the `RUN` to the file didn't work. I had to apply `chmod` directly to the local file. Let me know if there's an alternative since this meant we had to update the readme for developers since this was an issue where Mac only didn't have permissions, and there was no issues on Windows – mtpultz Jan 05 '21 at 21:40
  • The above will work in case of multi-stage build, if you consuming from host then set permission on host as mentioned but that might be the case if you are using mounting? – Adiii Jan 09 '21 at 02:32
  • Applying the permission locally did worked for me on macos. – Leonardo Santos Aug 16 '22 at 23:41