I am trying to containerize a .net MVC application, but when I run the image am getting the error like below
user@tuser:~/sam/WebApp$ docker run -p 8000:80 sam:latest
Did you mean to run dotnet SDK commands? Please install dotnet SDK from: https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
user@user:~/sam/WebApp$
And my Dockerfile looks like
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
COPY /bin/Release/Publish /app
ENTRYPOINT ["dotnet", "WebApp.dll"]
Where am I going wrong?
Late answer, but pretty common issue so I'll answer it.
This usually happens if the dll targeting argument in your entrypoint doesn't exist. There are other possibilities if you're exporting, tar-ing and reimporting assets, but that's probably not what we're dealing with here.
In your case, the copy operation is pointing at a root relative file location. I assume that you're not publishing to {system root/}bin/Release/Publish, and your dockerfile is located in the root of your project.
To solve this, you should perform copy operations relative to the directory your dockerfile is in, and specify copy operations using a directory relative path (./etc).
Example that works from my testing:
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
COPY ./bin/Release/Publish /app
ENTRYPOINT ["dotnet", "WebApi.dll"]
To see if it works, examine the resulting container by launching with a cmd override:
docker run -it --rm sam:latest /bin/sh
...
pwd #ensure workdir is app
ls -la #ensure that your application is copied here
If you want to investigate deeper, you can use docker run to override your entrypoint and experiment with different launch configurations to see the output. The commands you'll need are as follows:
docker run -it --rm --entrypoint {dotnet executable} {image}:{tag} {non-existent dll}
Example of output when targeting a non-existent dll via override on an otherwise working container:
➜ docker run -it --rm --entrypoint dotnet sam:latest weebles.dll
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409