[英]How to pass Command Line Arguments to .NET Console App through docker run (Docker for Windows)
I'm quite new in Docker word and I would like to pass arguments to my script from docker run.我对 Docker 字很陌生,我想将 arguments 从 docker 运行传递给我的脚本。 My C# code looks like:
我的 C# 代码如下所示:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello: " + args[0]);
}
}
And my Docker file is the following:我的 Docker 文件如下:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build
WORKDIR /app
COPY MediumDemo.csproj .
RUN dotnet restore MediumDemo.csproj
COPY . .
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/core/runtime:3.1 as runtime
WORKDIR /app
COPY --from=build /app/out ./
ENTRYPOINT ["dotnet", "Demo.dll"]
This is old, but for anyone who might be looking at it, you have to combine ENTRYPOINT with CMD in your Dockerfile, as follows:这是旧的,但对于任何可能正在查看它的人,您必须在 Dockerfile 中将 ENTRYPOINT 与 CMD 结合起来,如下所示:
ENTRYPOINT [ "dotnet", "Demo.dll" ]
CMD [ "arg0" ]
Then run it:然后运行它:
docker run -it Demo myarg
And you should see the output you expect.您应该会看到您期望的 output。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.