Distroless weird issue chmod

Viewed 12

I am trying to copy the outputs to distroless image The scripts folder contain a python file named start

FROM <some image> as custom-image


RUN mkdir scripts

COPY scripts/start scripts/start


FROM gcr.io/distroless/python3
COPY --from=custom-image /scripts /scripts

when I run the container and go into the terminal:

# cd scripts
# ./start
/bin/sh: 3: ./start: Permission denied
#

Now when I add the chmod line:

RUN chmod +x scripts/start

FROM gcr.io/distroless/python3
COPY --from=custom-image /scripts /scripts

and I attempt to run the start script in terminal again:

/bin/sh: 3: ./start: not found
1 Answers

How are you trying to run this script "in terminal"?

Your final image already has an ENTRYPOINT ([/usr/bin/python3.9]):

docker inspect --format='{{.Config.Entrypoint}}' gcr.io/distroless/python3

So your final stage could look something like this:

FROM gcr.io/distroless/python3
COPY --from=custom-image /scripts /scripts

RUN chmod +x scripts/start

CMD ["/scripts/start"]

I also added the chmod here since it makes more sense to do it in the final image then to do it before and hope that the COPY operation maintains permissions.

If you don't want the CMD then you can just add /scripts/start at your docker run <final_image> script.

Related