0
votes

I am creating a docker golang image, but my golang app needs to read a config.yaml on start. I tried to add the file as shown in the dockerfile below:

FROM golang:alpine as builder
# Install git + SSL ca certificates
RUN apk update && apk add git && apk add ca-certificates
# Create appuser
COPY . $GOPATH/src/github.com/user/app/
WORKDIR $GOPATH/src/github.com/user/app/
#get dependancies
RUN go get -d -v
#build the binary
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /go/bin/app
# STEP 2 build a small image
# start from scratch
FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
ADD ./config.yaml /go/bin/app/
# Copy our static executable
COPY --from=builder /go/bin/app /go/bin/app
EXPOSE 3000
ENTRYPOINT ["/go/bin/app"]

But I get the following error:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/go/bin/app\": permission denied": unknown.

5
The error pretty much explains the problem: It cannot execute /go/bin/app because permission is denied. Most likely, the execute bit isn't set. - Flimzy
/go/bin/app is a directory. - David Maze

5 Answers

3
votes

The problem is in the permission of execution of app, try to chmod +x to /go/bin/app after copying.

RUN chmod a+x /go/bin/app 
2
votes

I think you will have to run the below command, after copying the files

RUN chmod 700 /go/bin/app
2
votes

As others have pointed out, the executable does not seem to have the executable bit set.

Since the scratch image does not include even the shell, you cannot change the file permissions in that block. But you can do it in the block before the scratch:

...
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /go/bin/app
RUN chmod +x /go/bin/app
# STEP 2 build a small image
...
0
votes

For persons seeing similar error while trying to execute a shell script, there is a suggestion on this github issue. You could check if it'll work for you

0
votes

I had the same problem, but turns out the problem was that I was trying to run my main function in a non main package. I was a very weird error for this problem, but running it locally first gave me the answer