如何将命令行参数传递给docker run并打印?

时间:2018-08-10 14:58:13

标签: c# docker .net-core

我创建了一个具有docker(linux)支持的.Net core 2.1控制台应用程序。这是系统生成的Dockerfile

FROM microsoft/dotnet:2.1-runtime AS base
WORKDIR /app

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY MyApp/MyApp.fsproj MyApp/
RUN dotnet restore MyApp/MyApp.fsproj
COPY . .
WORKDIR /src/MyApp
RUN dotnet build MyApp.fsproj -c Release -o /app

FROM build AS publish
RUN dotnet publish MyApp.fsproj -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyApp.dll"]

控制台程序只是打印出参数。 (Console.WriteLine("The args are {0}", args);

但是,docker run MyApp:dev不打印任何内容。并且docker run MyApp:dev ABC出现以下错误。

  

C:\ Program Files \ Docker \ Docker \ Resources \ bin \ docker.exe:来自守护程序的错误响应:OCI运行时创建失败:container_linux.go:348:启动容器进程导致“ exec:\“ ABC \”: $ PATH中找不到可执行文件”:未知。

我尝试了docker run -it MyApp:dev dotnet /app/MyApp.dll ABC,但出现了

错误
  

您是要运行dotnet SDK命令吗?请从以下位置安装dotnet SDK:     http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

运行docker run -it MyApp:dev dotnet显示dotnet的用法。

PS C:\Temp> docker run -it MyApp:dev dotnet

Usage: dotnet [options]
Usage: dotnet [path-to-application]

Options:
  -h|--help         Display help.
  --info            Display .NET Core information.
  --list-sdks       Display the installed SDKs.
  --list-runtimes   Display the installed runtimes.

我尝试了docker run -it MyApp:dev bash,发现目录/app为空。 find . -name MyApp.dll找不到任何东西?

1 个答案:

答案 0 :(得分:2)

看起来您正在做的事情应该可以工作。我刚刚在这里进行了回购:

https://github.com/rquackenbush/DotNetCoreArgs

构建后:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.4.1/jspdf.debug.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/2.3.4/jspdf.plugin.autotable.js"></script>

我能够跑步:

docker build .

然后我得到了

docker run <imageid> ABC