如何打开文件并读取 Dockerfile 中的内容

发布于 2025-01-15 07:31:35 字数 356 浏览 4 评论 0原文

我有一个 docker 文件,我需要在其中打开一个文件并获取数据。如果数据是 dev,我将传递一个参数(dev 应用程序),如果它没有将另一个参数(prod 应用程序)传递给 sh 文件。应该是这样的

f=open config.txt
data=f.read()
if data=dev
app=dev application
else
app=prod application

ENTRYPOINT ["./entry.sh app"]

,我试图将参数传递给 .sh 文件 (entry.sh)。这样我就可以在entry.sh 文件中使用传入的参数。请帮助我如何以正确的方式做到这一点。 我是这个 Dockerfile 的新手。

I have a docker file where i need to open a file and get the data .If the data is dev, i am passing a argument(dev application) and if it is not passing another argument(prod application)to the sh file. It should be something like

f=open config.txt
data=f.read()
if data=dev
app=dev application
else
app=prod application

ENTRYPOINT ["./entry.sh app"]

here i am trying to pass the argument to the .sh file (entry.sh).so i can use the incoming argument in the entry.sh file. Please help me how to do it in a correct way.
I am new to this Dockerfile.

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

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

发布评论

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

评论(1

御弟哥哥 2025-01-22 07:31:35

您可以在构建 docker 映像时使用 ARG 参数传递参数,如下所示。在构建时,您可以传递诸如 docker build --build-arg ENV_ARG=dev 之类的值

DOCKER FILE CODE SAMPLE

ARG ENV_ARG=prod
ENV ENVIRONMENT=$ENV_ARG
CMD ["sh", "-c", "entry.sh ${ENVIRONMENT}"]

You can pass arguments while building the docker image by using the ARG parameters like this. while building you can pass values like docker build --build-arg ENV_ARG=dev

DOCKER FILE CODE SAMPLE

ARG ENV_ARG=prod
ENV ENVIRONMENT=$ENV_ARG
CMD ["sh", "-c", "entry.sh ${ENVIRONMENT}"]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文