简体   繁体   English

Distroless 奇怪的问题 chmod

[英]Distroless weird issue chmod

I am trying to copy the outputs to distroless image The scripts folder contain a python file named start我正在尝试将输出复制到 distroless 映像scripts文件夹包含一个名为start的 python 文件

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:当我将容器和 go 运行到终端时:

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

Now when I add the chmod line:现在当我添加 chmod 行时:

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:我尝试再次在终端中运行start脚本:

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

How are you trying to run this script "in terminal"?您如何尝试“在终端”中运行此脚本?

Your final image already has an ENTRYPOINT ( [/usr/bin/python3.9] ):您的最终图像已经有一个入口点( [/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.我还在此处添加了chmod ,因为在最终图像中执行此操作比之前执行此操作更有意义,并希望COPY操作保持权限。

If you don't want the CMD then you can just add /scripts/start at your docker run <final_image> script.如果你不想要CMD那么你可以在你的 docker 添加/scripts/start docker run <final_image>脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM