MMS • Edin Kapic
Article originally posted on InfoQ. Visit InfoQ
Microsoft announced on August 25th that .NET 7 SDK will include support for creating containerised applications as part of a build publish process, bypassing the need for explicit Docker build phase.
The rationale behind this decision was to simplify boilerplate Docker code and to reduce developer cognitive load, making it possible to build containerised applications in .NET faster than before. Developers can use the generated containers in local development or leverage it to build images as part of a CI/CD pipeline. The reactions of the developer community have been cautiously positive so far.
Microsoft’s Chet Husk, product manager for .NET SDK, explains that in order to build this feature they had to add support for handling TAR files directly into .NET. It allowed them to change and update Docker image files, which are packaged as TAR files according to the Open Container Initiative specification, during the usual .NET build process. All the information needed for building a container image of the .NET app is already present in the moment of the build and the .NET SDK was extended to include the container image build process written in C#.
A Docker image can have many configuration settings. In the .NET SDK image build process, these configurations are exposed as properties on the project level. For example, an ASP.NET Core project has a default base container image from the Azure container registry. If you want to change it to a different base image, you would have to change the ContainerBaseImage
property in the project file and point it to a new image. The build process will also take the assembly name of the project as the image name, which is also possible to override using ContainerImageName
project property.
A major limitation is that Dockerfile RUN commands are not supported. It seems to be a design decision due to the scope of .NET build process (In Mr Husk’s words: There’s no way of performing RUN commands with the .NET SDK). Dockerfile RUN commands enable you to build intermediate images by running operating system commands on the image being built, usually to install a tool or change a system configuration. As a workaround, Microsoft suggests to build a base image with RUN commands using Docker and then specify that image as a base image when building containers using .NET SDK.
In order to try this new feature in .NET 7, you will need to have Docker installed on your development machine, at least for now. The dependency on Docker is because the SDK is still relying on it for providing authentication to container registries. However, Docker is still needed to run the generated container image.
The feature has support only for Linux images for the moment. Microsoft states in the project milestone at GitHub that Windows images and container registry authentication will be solved before .NET 7 release, together with other image customization possibilities.
.NET 7 is currently in preview 7 and expected to be released in November 2022.