Chapter 12. .NET Core, Linux, and Containers

Microservices are the latest rage (or fad, depending on your view), and they go hand in hand with Linux containers. Realizing that a VM is overkill for running one microservice, Linux containers fit the bill perfectly. Small, quick to create, and highly portable, containers are here to stay.

Although .NET is new to the Linux world, it is already a viable choice for creating container-based microservices. Where the old .NET required large swaths of disk space and memory, the new, more modular and lightweight version means that using a container is a valid choice. For example, the difference between a RHEL image and a RHEL image with .NET is only 140 MB. Clearly, this is not your father’s .NET.

Creating a container image using the Red Hat image as a base involves a few tricks. This is because the image supplied by Red Hat is intended for use with their OpenShift container platform.

Associated source code

The source code used was created in Chapter 5.

Building the Image

For now, let’s see how to build an image that we can use outside of OpenShift. We’ll start by creating a new .NET project in a new directory:

mkdir mvc_docker
cd mvc_docker
dotnet new -t web

Remember to change the Program.cs class to use the proper URL: http://0.0.0.0:5000.

With the basic MVC application built, it’s time to construct the image. Note that for this example you will need to have your VM registered with the Red Hat subscription manager. This is because when ...

Get Transitioning to .NET Core on Red Hat Enterprise Linux now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.