.NET Containers advancements in .NET 8

An agile-minded senior developer with a proven track record spanning over 15 years of developing innovative end-to-end business solutions. Have experience in architecture, development, test, UX, and team lead. Designed, led, developed, and released solutions for different areas including eLearning, law, telecommunication, travel&tourism, insurance, and fraud detection. Focus on clean architecture, clean code, and satisfied customers. Tech stack is mainly full-stack development in the .NET ecosystem and Azure.
This is a summary of .NET Containers advancements in .NET 8 on .Net Conf 2023.
It is requied from communitity for .Net Container Images to be
Small (registry pull faster)
Secure (non-root; no shell or package manager)
Compliant (minimal dependencies, easy audit)
Composable (e.g. add locallication when needed)
Compatible (glibc vs musl libc)
Supported (part of a support contract / lifecycle)
Ubuntu Chiseled .NET images
Ubuntu Chiseled .NET images are a type of "distroless" container image that contain only the minimal set of packages .NET needs, with everything else removed. These images offer dramatically smaller deployment sizes and attack surface by including only the minimal set of packages required to run .NET applications.
Please see the Ubuntu Chiseled + .NET documentation page for more info.
Container Size Improvements

.Net Containers in General

How to Publish Your Application?
First add the below package from Nuget.
dotnet add package Microsoft.NET.Build.Containers --version 8.0.100
Then, publish your container using .NET CLI. I am using -r linux-x64, because I am on Windows.
dotnet publish -t:PublishContainer -r linux-x64
Then your application is published as a container to your local registry without any Dockerfile as below.

However, the size of the image will be big. We need to shrink the size of the container.

To shrink, add the PublishTrimmed and ContainerFamily to your csproj file.
<PropertyGroup>
....
<PublishTrimmed>true</PublishTrimmed>
<ContainerFamily>jammy-chiseled</ContainerFamily>
....
<PropertyGroup>
Then publish your project again.
dotnet publish -t:PublishContainer -r linux-x64 -p ContainerImageTag=chiseled
You will see that the size is reduced now.

You can also publish your app as Native AOT. Add the below to your csproj file.
<PublishAot>True</PublishAot>
dotnet publish -t:PublishContainer -r linux-x64 -p ContainerImageTag=aot
You can also specify the base image for the container.
<ContainerBaseImage>mcr.microsoft.com/dotnet/nightly/runtime:8.0</ContainerBaseImage>
I believe that creating containers without Dockerfile is a life-saving feature for developers. You can check the documentation for more information.






