.NET Core on Red Hat platforms
In this article, we look at the various ways .NET Core is made available on Red Hat platforms. We start with an overview of the available platforms, and then show how to install .NET Core on each of them.
Let’s start with the overview. If you are familiar with these platforms already, you can skip to the sections that cover specific platforms.
From an operating system point of view, we’ll look at four distributions:
- Fedora is a community maintained distribution that moves fast. It is a great option for developers who want access to the latest development tools and the latest kernel.
- Red Hat Enterprise Linux (RHEL) is a long-term support (LTS) distribution by Red Hat that is based on Fedora.
- CentOS is a community maintained downstream rebuild of Red Hat Enterprise Linux.
- CentOS Stream is a rolling preview distribution of future Red Hat Enterprise Linux versions.
All of these distributions are Free as in Freedom, so the software is available and open for change. Fedora and CentOS have no cost (Free as in Beer). For Red Hat Enterprise Linux, you pay a support subscription to Red Hat. For development purposes, however, you can use a no-cost Red Hat Developer subscription and download Red Hat Enterprise Linux, as well as our other products and tools at no cost.
Most public cloud vendors support creating Red Hat Enterprise Linux- and CentOS-based virtual machines (VMs). The VMs based on RHEL are supported by Red Hat, and the VMs based on CentOS are supported by the CentOS community.
With container technology, operating systems are now also packaged into container images. These images contain packages from the OS, but not the kernel. Red Hat provides Red Hat Enterprise Linux 7- and RHEL 8-based images. Red Hat Enterprise Linux 8-based images are based on the Universal Base Image (UBI). For Red Hat Enterprise Linux 7, some images are provided as UBI images and others as non-UBI images. The RHEL 7 non-UBI images are hosted on registry.redhat.io and require subscription credentials to be pulled. The UBI images are hosted on registry.access.redhat.com and require no subscription for download. These images may be used in production without a Red Hat subscription, on any platform. However, when the UBI images run on a Red Hat Enterprise Linux platform, subscribers get support from Red Hat. The CentOS community also provides images that are hosted on registry.centos.org.
For running container-based applications, Red Hat provides Red Hat OpenShift, which is based on Kubernetes. Kubernetes provides the core functionality for scheduling containers across multiple machines. OpenShift packages Kubernetes in a form that is usable, deployable, and maintainable. Red Hat provides a supported version of OpenShift that can be deployed on-prem and in public clouds (e.g., Azure, AWS, and GCP). Red Hat OpenShift is based on the open source, upstream
okd project. To run OpenShift on your development machine, you can use Red Hat CodeReady Containers (CRC) for OpenShift 4.x, and the Red Hat Container Development Kit (CDK) for OpenShift 3.x.
.NET Core on each platform
Now, let’s take a look at how to install .NET Core onto each Red Hat platform.
.NET Core on Fedora
.NET Core on Fedora is built by the Fedora .NET Special Interest Group (SIG). Because .NET Core doesn’t meet the Fedora packaging guidelines, it is distributed from a separate repository.
To install .NET Core on Fedora, you need to enable the
copr repository and install the
$ sudo dnf copr enable @dotnet-sig/dotnet $ sudo dnf install dotnet-sdk-2.1
When possible, the SIG also builds preview versions of .NET Core. These preview versions are distributed from a separate repository:
$ sudo dnf copr enable @dotnet-sig/dotnet-preview $ sudo dnf install dotnet-sdk-3.1
For more information about running .NET Core on Fedora, see the Fedora .NET documentation.
.NET Core on Red Hat Enterprise Linux 7 and CentOS 7
On Red Hat Enterprise Linux 7 and CentOS 7, .NET Core versions are packaged into their own software collection (SCLs). This method of packaging allows .NET Core to include libraries that are newer than those provided by the base OS.
To install .NET Core on Red Hat Enterprise Linux, the machine needs to be registered with the Red Hat subscription management system. Depending on the OS flavor (e.g., Server, Workstation, or HPC Compute node), you need to enable the proper .NET Core repository:
$ sudo subscription-manager repos --enable=rhel-7-server-dotnet-rpms $ sudo subscription-manager repos --enable=rhel-7-workstation-dotnet-rpms $ sudo subscription-manager repos --enable=rhel-7-hpc-node-dotnet-rpms
Next, the SCL tooling needs to be installed:
$ sudo yum install scl-utils
Now we can install a specific version of .NET Core:
$ sudo yum install rh-dotnet21 -y
To use the .NET Core SCL, we first need to enable it. For example, we can run
bash in the SCL by running:
$ scl enable rh-dotnet30 bash
For more information about running .NET Core on Red Hat Enterprise Linux 7, see the .NET Core Getting Started Guides.
.NET Core on Red Hat Enterprise Linux 8/CentOS 8
On the newer RHEL 8, .NET Core is included in the AppStream repositories, which are enabled by default. A version of .NET Core can be installed by running:
$ sudo dnf install dotnet-sdk-2.1
For more information about running .NET Core on Red Hat Enterprise Linux 8, see the .NET Core Getting Started Guides.
.NET Core in containers
Two images are provided per the different .NET Core versions: a runtime image that contains everything necessary to run a .NET Core application, and an SDK image that contains the runtime plus the tooling needed to build applications.
Table 1 shows the names of the images for .NET Core 2.1. For other versions, just change the version numbers in the name.
|Base image||SDK/runtime image|
Note: Depending on the version, an image might not (yet) be available for a specific base. For example, CentOS images are made available by the CentOS community after Red Hat Enterprise Linux images are created by Red Hat.
The following example prints out the SDK version that is available in the .NET Core 2.1
$ podman run registry.access.redhat.com/ubi8/dotnet-21:2.1 dotnet --version 2.1.509
.NET Core on OpenShift
The .NET Core images provide an environment for running and building .NET Core applications. They are also compatible with OpenShift’s source-to-image (S2I) build strategy. This factor means that the OpenShift container platform can build a .NET Core application from source.
.NET images are imported in OpenShift using the OpenShift CLI client (
oc) with an image stream definition file from the
s2i-dotnetcore GitHub repo. The file differs depending on the base image, as shown in Table 2.
|Base image||Image stream definition|
Retrieving the Red Hat Enterprise Linux 7 images requires authentication. Registry Authentication describes how you can set up the pull secret.
The image streams can be imported using
oc. For example, to import the
ubi8-based images, run:
$ oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/dotnet_imagestreams_rhel8.json
Note: If there are already image streams present for .NET Core, you must use
replace instead of
s2i-dotnetcore repository includes a script for installing these image streams on Windows, Linux, and macOS. See Installing for more information. This script can also create the pull secret needed for pulling the Red Hat Enterprise Linux 7 images.
Once the image streams are installed, OpenShift can directly build and deploy an application from a Git repo, for example:
$ oc new-app dotnet:3.1~https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnetcore-3.1 --context-dir=app
For more information about using .NET Core on OpenShift, see the corresponding chapter in the .NET Core Getting Started Guides.
In this article, you got an overview of the Red Hat platforms that support .NET Core, and how to install .NET Core on each of them.