I have a .NET Core application with 4 class libraries pointing to .NET framework 4.7.2.
Visual Studio created this Docker file by default:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["API/API.csproj", "API/"]
COPY ["Service/Service.csproj", "Service/"]
COPY ["DataAccess/DataAccess.csproj", "DataAccess/"]
COPY ["DBModels/DBModels.csproj", "DBModels/"]
COPY ["DTO/DTO.csproj", "DTO/"]
RUN dotnet restore "API/API.csproj"
COPY . .
WORKDIR "/src/API"
RUN dotnet build "API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "API.dll"]
Apart from API project all others are of .NET 4.7.2, on running docker build command I get below error :
/usr/share/dotnet/sdk/3.1.423
/Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.7.2 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application
Following some multi stage build links I tried to change my docker file as below:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8.1 AS dotnet-framework-build
WORKDIR /src
COPY ["Service/Service.csproj", "Service/"]
COPY ["DataAccess/DataAccess.csproj", "DataAccess/"]
COPY ["DBModels/DBModels.csproj", "DBModels/"]
COPY ["DTO/DTO.csproj", "DTO/"]
RUN dotnet build "DTO/DTO.csproj" -c Release -o /app/build
RUN dotnet build "DBModels/DBModels.csproj" -c Release -o /app/build
RUN dotnet build "DataAccess/DataAccess.csproj" -c Release -o /app/build
RUN dotnet build "Service/Service.csproj" -c Release -o /app/build
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["API/API.csproj", "API/"]
COPY --from=dotnet-framework-build /src .
RUN dotnet restore "API/API.csproj"
COPY . .
WORKDIR "/src/API"
RUN dotnet build "API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "API.dll"]
Then I get this error:
Load metadata for mcr.microsoft.com/dotnet/framework/sdk:4.8.1. failed to solve with frontend dockerfile.v0: failed to create LLB definition: no match for platform in manifest
sha256:541fb3066edb782893eb24ce2a2f4da3de9b97d803c026094b9f9e5c301b7cb1: not found
However when I tried to create a new sample .NET Core app without any .NET framework dependencies, then I was able to create an image.
Any help or pointers to create image of .NET Core 3.1 using .NET Framework 4.7.2 will be helpful. Thanks !