如何在运行时将命令行参数传递给Docker映像中的dotnet dll? [英] How to pass command line arguments to a dotnet dll in a Docker image at run time?

查看:67
本文介绍了如何在运行时将命令行参数传递给Docker映像中的dotnet dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

处理我的第一个Docker映像.这是一个使用CMD启动的dotnet程序(Docker中仅允许一个CMD).我想在运行时向程序传递一个参数(API密钥).经过一番谷歌搜索后,找不到明确的答案.入口点似乎没有帮助.也许是ENV,但似乎ENV仅适用于Docker.我的Dockerfile:

Working on my first Docker image. It is a dotnet program that uses CMD to launch (only one CMD allowed in Docker). I would like to pass the program an argument (an API key) at runtime. After some googling, not finding a clear answer. Entrypoint doesn't seem helpful. Maybe ENV, but it seems ENV is only for Docker. My Dockerfile:

FROM microsoft/dotnet
WORKDIR /app
COPY . /app
CMD [ "dotnet",  "/app/netcore/Somename.dll"]

谢谢

推荐答案

如果Docker使用 JSON ENTRYPOINT CMD 连接到单个命令行中像您的示例中那样,strong>表示法.

Docker joins ENTRYPOINT and CMD into single command line, if both use JSON notation, like in your example.

这是JSON表示法: CMD ["dotnet","/app/netcore/Somename.dll"]

This is JSON notation: CMD [ "dotnet", "/app/netcore/Somename.dll"]

这是外壳符号: CMD dotnet/app/netcore/Somename.dll

您需要了解的另一件事-在 docker run ...中写的是什么...< image_name>... 之后-被视为 CMD .

Another thing you need to know - what is written in docker run ... <image_name> ... after - considered as CMD.

总结一下.

  1. 命令行的常量(不可变)部分,例如 dotnet foo.dll ,您可以放入 ENTRYPOINT .

可变部分,像其他参数一样,随 docker run 提供,并有选择地将默认值放置在 Dockerfile CMD >

Variable part, like additional arguments, you supply with docker run and optionally put defaults to CMD in Dockerfile

示例:

Dockerfile

...
ENTRYPOINT ["dotnet", "/app/netcore/Somename.dll"]
CMD ["--help"]

命令行1:

docker run ... <your image name> --environment=Staging --port=8080 

将导致 dotnet/app/netcore/Somename.dll --environment = Staging --port = 8080

命令行2:

docker run ... <your image name>

将生成 dotnet/app/netcore/Somename.dll --help .-help 来自Dockerfile中定义的默认值.

Will result in dotnet /app/netcore/Somename.dll --help. --help comes from default value, defined in Dockerfile.

这篇关于如何在运行时将命令行参数传递给Docker映像中的dotnet dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆