Run Windows docker container to host Rest Api in dotnet 6.0 with a dependency on dll with .net framework 3.5

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.

I edited your post. Please, use code blocks (</> button) when you insert codes, error messages or anything with special characters in Markdown and don’t use dashes as separators like ------- in a new line because that will make the above line a heading with a huge fontsize when you don’t really want that.

I don’t use dotnet, but this seemed strange to me:

ENTRYPOINT ["dotnet", "EcuApi.dll"]

so I checked the documentation

Is that EcuApi is an app that runs in the foreground? I guess it is, I just want to make sure.

As you noticed, you can’t use multi-stage buuld to have two base images for your image. You can use one and install everything else using RUN instructions or COPY as you did. Since I am not familiar with dotnet, I can just give you some advice and ask questions to investigate the issue.

Is there any error messages even if they are not clear? It may be clear for someone else.

When I don’t get a clear error message, I just start a container with a shell and install everything interactively, start the service and test in an other terminal (Powershell in your case) or from a browser. That way you can try to search for logs files in the container if the standard output and error stream does not have any helpful content.

I think the problem here (in addition to @rimelek observation) is that the image you’re using on the first stage calls out a Nano Server base image (see ASP.NET Core Runtime by Microsoft | Docker Hub), but then you call the .Net Framework image, which uses the Server Core image (See .NET Framework SDK by Microsoft | Docker Hub).

So, to clarify: .Net (formerly known as .Net Core) has Nano Server and Server Core images. .Net Framework only works on Server Core images. You can’t mix the base image that .Net runs on top of. My recommendation is to try to use the .Net Framework image on all stages (which uses Server Core). Or at least ensure the Server Core is being used as base at all times. To do that, you have to find the right tag on the first link above.