I have a Dockerfile like this:
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Project/Project.csproj", "Project/"]
COPY ["Reference/Reference.csproj", "Reference/"]
RUN dotnet restore "Project/Project.csproj"
RUN dotnet restore "Reference/Reference.csproj"
COPY . .
WORKDIR "/src/Project"
RUN dotnet build "Project.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Project.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Project.dll"]
but when i want to build and run it with docker build -f Dockerfile -t mytag . && docker run --name myproject mytag
i get an error after the build:
You must install or update .NET to run this application.
2022-11-09T15:48:22.642099385Z
2022-11-09T15:48:22.642104961Z App: /app/Project.dll
2022-11-09T15:48:22.642108153Z Architecture: x64
2022-11-09T15:48:22.642111392Z Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64)
2022-11-09T15:48:22.642115860Z .NET location: /usr/share/dotnet/
2022-11-09T15:48:22.642119020Z
2022-11-09T15:48:22.642122144Z No frameworks were found.
Why is this happening?
CodePudding user response:
The runtime
image is meant for console apps. Yours is an ASP.NET app, so you should use the aspnet
runtime image instead.
Replace
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
with
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base