How to pass command line argument to docker run and print it?
Clash Royale CLAN TAG#URR8PPP
How to pass command line argument to docker run and print it?
I created a .Net core 2.1 console application with docker (linux) support. Here is the system generated Dockerfile
.
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"]
The console program just prints out the argument. (Console.WriteLine("The args are 0", args);
)
Console.WriteLine("The args are 0", args);
However, docker run MyApp:dev
doesn't print anything. And docker run MyApp:dev ABC
got the following error.
docker run MyApp:dev
docker run MyApp:dev ABC
C:Program FilesDockerDockerResourcesbindocker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: "ABC": executable file not found in $PATH": unknown.
I tried docker run -it MyApp:dev dotnet /app/MyApp.dll ABC
and it got the error of
docker run -it MyApp:dev dotnet /app/MyApp.dll ABC
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
Running docker run -it MyApp:dev dotnet
shows the Usage of dotnet
.
docker run -it MyApp:dev dotnet
dotnet
I tried docker run -it MyApp:dev bash
and found the dirctory /app
is empty. find . -name MyApp.dll
cannot find anything?
docker run -it MyApp:dev bash
/app
find . -name MyApp.dll
1 Answer
1
It looks like what you're doing should work. I just made a repo here:
https://github.com/rquackenbush/DotNetCoreArgs
After building:
docker build .
I was able to run:
docker run <imageid> ABC
And I got:
Hello World!
There are 1 args.
ABC
docker run -it dotnet /app/MyApp.dll ABC
"Unable to find image 'dotnet:latest' locally C:Program FilesDockerDockerResourcesbindocker.exe: Error response from daemon: pull access denied for dotnet, repository does not exist or may require 'docker login'."
Apologies - I left off the image name to run
– RQDQ
Aug 10 at 15:14
No problem, I tried it with the image name and got the error of
Did you mean to run dotnet SDK commands? Please install dotnet SDK from: http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
– ca9163d9
Aug 10 at 15:16
Did you mean to run dotnet SDK commands? Please install dotnet SDK from: http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
Ahh - to make sure that
dotnet
doesn't try to use the arguments you're passing for its own needs, you have to add --
– RQDQ
Aug 10 at 15:17
dotnet
--
I got the same dotnet SDK error after added
--
. I tried it in both powershell and cmd.– ca9163d9
Aug 10 at 15:19
--
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I tried
docker run -it dotnet /app/MyApp.dll ABC
and it got teh error of"Unable to find image 'dotnet:latest' locally C:Program FilesDockerDockerResourcesbindocker.exe: Error response from daemon: pull access denied for dotnet, repository does not exist or may require 'docker login'."
Should the image be specified in the command line?– ca9163d9
Aug 10 at 15:10