At the beginning of December, Microsoft announced upcoming changes to Windows Server Core container images that would make them 40% smaller. In a post on the .NET Blog, .NET Team Program Manager Richard Lander says that Insider images are 40% smaller than the latest (patched) 1903 images, based on the images in the Windows Server Core insiders Docker repo. Additionally, startup times to Windows PowerShell are 30-45% faster. Lander says that the improvements should apply in any scenario where Windows Server Core container images are used and will be most beneficial for scaling apps, continuous integration and continuous delivery (CI/CD), and other situations where images are pulled without using a Docker image cache or where faster startup times are required.
How Did Microsoft Reduce the Image Size by 40 percent?
Windows Server Core images include a series of pre-compiled .NET native images that are generated using a tool called Ngen.exe to improve startup performance. But the downside is that it also makes image size grow. The current Insider Windows Server Core images now include a significantly smaller set of NGEN images. A larger set of images is included in the .NET Framework runtime images, also based on Server Core, but are also smaller because Microsoft makes sure that there is only one copy of each NGEN image that target ASP.NET and PowerShell performance.
Investigations started at Microsoft a year ago based on the premise that the way the .NET Framework is packaged and installed doesn’t work well with Docker layers. On the back of this research, Microsoft defined three criteria to reduce image sizes.
- There should be a single copy of each file in the .NET Framework, across all container image layers published by Microsoft.
- NGEN images that are created by default should align with default use cases.
- Maintain startup performance as container image size is reduced.
Decreasing image size and maintaining startup performance was the biggest challenge as NGEN was the culprit for increased image size. To achieve its goals for the Windows Server Core base image layer, Microsoft made the following changes:
- Included a serviced copy of .NET Framework 4.8.
- Removed all NGEN images, except for mscorlib.dll, System.dll and System.Core.dll (32-bit and 64-bit).
In the .NET Framework runtime image layer, the changes are as follows:
- Included NGEN assemblies used by Windows PowerShell and ASP.NET only.
- Included only NGEN 64-bit assemblies.
The images are currently available for Insiders here at the windows/servercore/insider repo but should be generally available in the windows/servercore repo when Windows 10 20H1 becomes generally available in the first half of 2020. Microsoft says that container images needing best performance for .NET Framework or Windows PowerShell should use the dotnet/framework/runtime repo. While the images are bigger, they offer better performance.