Docker - Windows Container - Install DotNet Framework 472
You can use the same dockerfile which microsoft using for building their dotnetframework images here for SDK (https://github.com/microsoft/dotnet-framework-docker/blob/master/4.7.2/sdk/windowsservercore-ltsc2019/Dockerfile) or runtime (https://github.com/microsoft/dotnet-framework-docker/blob/master/4.7.2/runtime/windowsservercore-ltsc2019/Dockerfile)
If you really want to do this without using an existing image, then you could create a powershell script to download and install it, and then call this from within your dockerfile:
Write-Host ".Net 4.7.2 not installed. Downloading..."Invoke-WebRequest "http://go.microsoft.com/fwlink/?linkid=863265" -OutFile "NDP472-KB4054530-x86-x64-AllOS-ENU.exe"Write-Host "Installing .Net 4.7.2..."$exe = ".\NDP472-KB4054530-x86-x64-AllOS-ENU.exe"&$exe /q /norestart
The DockerFile (assuming you name your script InstallNetFramework.ps1 and it lives in the same folder as your DockerFile:
FROM microsoft/windowsservercore RUN mkdir c:\installADD /InstallNetFramework.ps1 c:\installRUN powershell c:\install\InstallNetFramework.ps1
But you are probably best using an image that already has .Net 4.7.2 installed because otherwise:
- It's going to be slow every time you need to build your image (waiting for it to d/l and install .Net 4.7.2 every time)
- You are going to need to update the download path should microsoft patch 4.7.2 in the future or move the download etc.
If you just do this once however, you could register this in your own personal Container Registry and use it as your base image for further DockerFiles (e.g. use this as the FROM)