在 ECR 映像中包含文件

发布于 2025-01-17 08:19:49 字数 307 浏览 0 评论 0原文

关于上传到 ECR 的图像有一个简单的问题 - 是否包含本地文件?例如,如果我有类似的内容:

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

我将构建图像并将其上传到公共 ECR 存储库。用户是否能够从 Docker 映像中运行 ./script.sh 或者他们需要在计算机上拥有一个名为 script.sh 的文件?

Just a quick question regarding images uploaded to ECR - are local files included? e.g. 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み零 2025-01-24 08:19:49

script.sh 文件肯定包含在图像中,还有另外两个问题导致图像最终无法工作。

Ted 在评论中已经提到过,script.sh 可能无法执行。

话虽如此,可能导致您认为 script.sh 不会包含在图像中的问题是它不在工作目录中。
您的复制语句是

COPY script.sh /script.sh

由于最后一部分是 /script.sh,以斜杠开头,该文件将被放置到图像的根目录。但是您已经将工作目录设置为 /app
加载入口点时,将找不到 script.sh,因为正在工作目录中搜索它。

让图像正常工作应该像删除 COPY 语句中的斜杠一样简单,因此正确的语句是:

COPY script.sh script.sh

要解决 script.sh 无法运行的可能问题,我建议使入口点像这样:

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

这样脚本是否可执行并不重要

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文