Reputation: 4594
I am trying to build a Docker image and run a container for my sample ASP.NET Core 3.1 app and am seeing
It was not possible to find any installed .NET Core SDKs
when I run the command
docker run --rm -it -p 8000:80 ppi
My Dockerfile is simple:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
COPY publish/ ./
ENTRYPOINT ["dotnet", "sampleapp.dll"]
and I am pre-building my app into the publish
folder. My folder structure looks as follows:
root/
source/
SampleApp.csproj
appsettings.json
Startup.cs
Program.cs
publish/
SampleApp.dll
SampleApp.exe
appsettings.json
SampleApp.deps.json
SampleApp.runtimeconfig.json
web.config
Dockerfile
SampleApp.sln
I created the image using the following command
docker build -t ppi
There are no issues with my sample app, as I'm able to launch it locally with the following command
dotnet publish/sampleapp.dll
What am I missing here? I've been working off of the following tutorials:
Upvotes: 1
Views: 13818
Reputation:
I had the same issue but did not want to build the app using the mcr.microsoft.com/dotnet/core/sdk:3.1-buster image. I discovered the shell running in the Linux container (bash) is case sensitive.
In your Dockerfile, change ENTRYPOINT ["dotnet", "sampleapp.dll"]
to ENTRYPOINT ["dotnet", "SampleApp.dll"]
.
On Windows 10 either command will work since the shell there is case insensitive.
"Works on my machine..." anyone?
Upvotes: 2
Reputation: 2804
I get this error on Windows, when trying to run the Published version, ie just trying to use the runtime, not the sdk.
The solution for me was to change this:
dotnet sample
to this:
dotnet sample.dll
Upvotes: 0
Reputation: 2246
This image mcr.microsoft.com/dotnet/core/aspnet:3.1
is a .NET Runtime.
The recommended way of creating a docker image is to copy the code inside a dotnet sdk image. And fire all the build commands inside the docker image.
Once done. You copy only the publish folder to a dotnet runtime image (the one you are using).
If you are using visual studio; use the Add Docker Support option to generate a Dockerfile. And everything should work like a charm.
The error message is a little cryptic in saying that not all the files are present for running the application.
Your Dockerfile should look like below:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["myaspnetapp.csproj", ""]
RUN dotnet restore "./myaspnetapp.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "myaspnetapp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "myaspnetapp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "myaspnetapp.dll"]
Upvotes: 7