"Permission denied" on file when running a docker container

Niklas picture Niklas · Oct 19, 2020 · Viewed 6.9k times · Source

I have a file that I can't edit but needs to run on in a docker container. Because the file doesn't have an extension, I have to use chmod for setting the file executable. But after I build the docker image from the docker file I always get a "permission denied" error

My docker file:

FROM alpine

COPY . /home/guestuser/bin/gateway

RUN apk add libressl-dev
RUN apk add libffi-dev

RUN pwd

WORKDIR /home/guestuser/bin/.
RUN ["chmod", "+x", "gateway"]

RUN pwd

CMD ["/home/guestuser/bin/gateway"]


EXPOSE 11878

I alwas get this error:

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

As I already mentioned, I am not able to edit the file I want to execute. What am I doing wrong?

Answer

Ganesh picture Ganesh · Oct 19, 2020

You may try this simple one.

FROM alpine
COPY . /home/guestuser/bin/gateway
RUN apk add libressl-dev
RUN apk add libffi-dev
WORKDIR /home/guestuser/bin/
RUN chmod -R 755 /home/guestuser
CMD ["/bin/bash", "/home/guestuser/bin/gateway"]

Otherwise, run sleep command login to container and see your commands works manually