Faizal Sidek
Faizal Sidek

Reputation: 196

How to use dotnet core on docker dotnet framework image

As per title, I want to use dotnet core on dotnet framework aspnet image. A little bit of background, I have ASP.NET (4.6) application with dotnet core libraries. Currently it is running on IIS. Now, I'm looking forward to dockerize this by using windows server core image. No particular reason, just looking to dockerize and modernize legacy application.

Problem is during runtime, the IIS inside aspnet doesn't recognize aspnetmodule. In IIS we normally install hosting bundle, how to do this on docker?

Thank you

Upvotes: 3

Views: 2119

Answers (2)

Vitalii Ivanov
Vitalii Ivanov

Reputation: 3251

Find download link of the .NET Core SDK you need here https://dotnet.microsoft.com/download/dotnet-core.

Here is sample for .NET Core 2.2

FROM mcr.microsoft.com/dotnet/framework/runtime:4.7.2 AS runtime

# Replace download URL with .NET Core SDK you need.
ADD https://download.visualstudio.microsoft.com/download/pr/7ae62589-2bc1-412d-a653-5336cff54194/b573c4b135280fb369e671a8f477163a/dotnet-sdk-2.2.100-win-x64.exe c:/setup

RUN C:/setup/dotnet-sdk-2.2.100-win-x64.exe /install /quiet

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

Upvotes: 0

Faizal Sidek
Faizal Sidek

Reputation: 196

Just for record keeping, am sharing this. What I did was I take the images from Microsoft and add installation for Hosting bundle. In this case, I'm using dotnet core 1.1:

# escape=`
ARG REPO=mcr.microsoft.com/dotnet/framework/runtime
FROM $REPO:4.8-windowsservercore-ltsc2019

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

ADD dotnetcore.1.0.16_1.1.13-windowshosting.exe /install/
RUN Add-WindowsFeature Web-Server; `
    Add-WindowsFeature NET-Framework-45-ASPNET; `
    Add-WindowsFeature Web-Asp-Net45; `
    Remove-Item -Recurse C:\inetpub\wwwroot\*; `
    Invoke-WebRequest -Uri https://dotnetbinaries.blob.core.windows.net/servicemonitor/2.0.1.6/ServiceMonitor.exe -OutFile C:\ServiceMonitor.exe

# Install Roslyn compilers and ngen binaries
RUN Invoke-WebRequest https://api.nuget.org/packages/microsoft.net.compilers.2.9.0.nupkg -OutFile c:\microsoft.net.compilers.2.9.0.zip; `
    Expand-Archive -Path c:\microsoft.net.compilers.2.9.0.zip -DestinationPath c:\RoslynCompilers; `
    Remove-Item c:\microsoft.net.compilers.2.9.0.zip -Force; `
    &C:\install\dotnetcore.1.0.16_1.1.13-windowshosting.exe /install /quiet | `
    &C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe install c:\RoslynCompilers\tools\csc.exe /ExeConfig:c:\RoslynCompilers\tools\csc.exe | `
    &C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe install c:\RoslynCompilers\tools\vbc.exe /ExeConfig:c:\RoslynCompilers\tools\vbc.exe | `
    &C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe install c:\RoslynCompilers\tools\VBCSCompiler.exe /ExeConfig:c:\RoslynCompilers\tools\VBCSCompiler.exe | `
    &C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe install c:\RoslynCompilers\tools\csc.exe /ExeConfig:c:\RoslynCompilers\tools\csc.exe | `
    &C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe install c:\RoslynCompilers\tools\vbc.exe /ExeConfig:c:\RoslynCompilers\tools\vbc.exe | `
    &C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe install c:\RoslynCompilers\tools\VBCSCompiler.exe  /ExeConfig:c:\RoslynCompilers\tools\VBCSCompiler.exe

ENV ROSLYN_COMPILER_LOCATION c:\\RoslynCompilers\\tools

EXPOSE 80

ENTRYPOINT ["C:\\ServiceMonitor.exe", "w3svc"]

I have no way to automate download for hosting bundle. You may need to download it from microsoft site: https://dotnet.microsoft.com/download/dotnet-core/2.2, choose runtime and hosting bundle.

Put it together with the Dockerfile so Docker can copy it into the image. This image can run on Windows Server 2019. For other version of Windows Server, you may need to use different tag.

P/S: Hosting bundle installation is a bit tricky, I used to extend the image but somehow the installation become ephemeral and lost. This is working for me, hope this helps.

Upvotes: 1

Related Questions