Distroless weird issue chmod

782 Views Asked by At

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

There are 1 best solutions below

3
Mihai On

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

# not needed
# RUN chmod +x scripts/start

CMD ["/scripts/start"]

I also added and commnented out the chmod here to point out that it is not needed. Since the entrypoint for the distroless image is /usr/bin/python3.9, what will actually the run in the end is /usr/bin/python3.9 scripts/start, which means the script doesn't need to be executable.

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