You would love to run your .NET applications as Linux containers instead of using Windows containers. However, there are situations that you have to run your .NET applications as Windows containers with servercore docker image due to your project having dependencies, such as a third party dll (could be even built by different department in your company) which demands your application to run on Windows servercore docker image. Worst case is sometimes your app is still on .NET 3.1 Core you do not have a servercore image for .NET Core 3.1. (For .NET 5,6,7,8 the Windows servercore images are available.. check here) Therefore you need to setup .NET Core 3.1 runtime on the servercore docker image. Let's see how we can achive this requirement.
Using below base image defintion in your docker file you could setup .NET Core 3.1
The follwing will allow you to use windows server core 2019 image.
Then you can setup .NET Core 3.1 runtime with below in your docker file.
# Install .NET Core 3.1 runtime SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] ADD https://dot.net/v1/dotnet-install.ps1 C:/setup/dotnet-install.ps1 RUN C:/setup/dotnet-install.ps1 -Runtime aspnetcore -Channel 3.1 -Version latest -InstallDir '/Program Files/dotnet' ENV DOTNET_ROOT="c:\Program Files\dotnet" # Add .NET Core to path RUN setx /M PATH $(${Env:PATH} + ';C:\Program Files\dotnet')
Once you setup your base image it can be used to run your app like below (how to build your app with dockerfile is skipped here for brevity).
No comments:
Post a Comment