简体   繁体   中英

Including files in ECR image

Just a quick question regarding images uploaded to ECR - are local files included? eg if I have something like:

FROM python:3.9.10-buster
RUN mkdir /app
WORKDIR /app
COPY script.sh /script.sh
ENTRYPOINT ["./script.sh"]

I'll build the image and upload it to a public ECR repository. Would users be able to run ./script.sh from within the Docker image or will they need to have a file called script.sh on their computer?

The script.sh file is certainly included in the image, there are two other problems that make the image not work in the end.

One was already mentioned in a comment by Ted, that being that script.sh may not be executable.

That being said, the problem that is likely causing you to think script.sh would not be included in the image, is that it's not in the working directory.
Your copy statement was

COPY script.sh /script.sh

Since the last part is /script.sh , beginning with a slash, the file will be put to the root of the image. However you already set the workdir to /app .
When the entrypoint is being loaded script.sh won't be found, since it's being searched for in the working directory.

Getting your image to work correctly should be as easy as removing that slash in the COPY statement, so the correct statement would be:

COPY script.sh script.sh

To resolve the possible problem of script.sh not being runnable, I'd recommend to make the entrypoint like this:

ENTRYPOINT ["sh", "script.sh"]

This way it doesn't matter weither or not the script is executable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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