I need to host a Rest API with .net core 6 on a Windows Docker container. This api will retrieve information from a locally installed dll which needs .net framework to be installed.
If I build and run the following build file with commands:
docker build -t ecuapi .
docker run -d -p 8082:80 --name EcuApi ecuapi
FROM mcr.microsoft.com/dotnet/aspnet:6.0 as base
COPY EcuApi/bin/x64/Debug/net6.0/ app/
WORKDIR /app
ENTRYPOINT ["dotnet", "EcuApi.dll"]
Note that the copy statement copies the project artefacts and needed dll files.
In this case the api is accessible via endpoint localhost :8082 and is available to handle calls.
Unfortunately, the calls will fail because I cannot retrieve data from the dll because .net framework 3.5 is not installed yet.
FROM mcr.microsoft. com/dotnet/framework/sdk
COPY EcuApi/bin/x64/Debug/net6.0/ app/
WORKDIR /app
SHELL [ "powershell" ]
RUN powershell "Set-Service -Name wuauserv -StartupType Manual; Install-WindowsFeature -Name NET-Framework-Features -Verbose"
ENTRYPOINT ["dotnet", "EcuApi.dll"]
This build file makes sure that .net framework 3.5 is installed (and it works fine). However the api does not work because the .net core installation is not done (localhost:8082 is not accessible).
Trying to combine this:
FROM mcr.microsoft. com/dotnet/aspnet:6.0 as base
COPY EcuApi/bin/x64/Debug/net6.0/ app/
WORKDIR /app
FROM mcr.microsoft. com/dotnet/framework/sdk as final
SHELL [ "powershell" ]
WORKDIR /sdk
RUN powershell "Set-Service -Name wuauserv -StartupType Manual; Install-WindowsFeature -Name NET-Framework-Features -Verbose"
COPY --from=base /app ./
ENTRYPOINT ["dotnet", "EcuApi.dll"]
Build is done successfully, but the api endpoint localhost:8082 is still not accessible. This is not strange as dot net core is not really installed. The multistage build does not add anything in this case.
test 4:
FROM mcr.microsoft. com/dotnet/framework/sdk as final
SHELL [ "powershell" ]
WORKDIR /sdk
RUN powershell "Start-Process -Wait -FilePath 'dotnet-hosting-6.0.6-win.exe' -ArgumentList '/S' -PassThru"
RUN powershell "Set-Service -Name wuauserv -StartupType Manual; Install-WindowsFeature -Name NET-Framework-Features -Verbose"
COPY --from=base /app ./
ENTRYPOINT ["dotnet", "EcuApi.dll"]
It successfully build the container but when I run this the container stops after a few seconds without a clear error message.
Can anybody help me further with this?
Do I need to use another base image? Note that I also tried to run the .net framework 3.5 installer on the mcr.microsoft.com/dotnet/aspnet:6.0
but such a container also stops after a few seconds when I run this.