One exciting feature in the recent release of Red Hat Enterprise Linux 8.1 is .NET Core 3.0. In this article, we will take a quick look at using .NET Core on Red Hat Enterprise Linux 8. We will cover installing .NET Core RPMs and using the RHEL-based Universal Base Image container images.
Installing .NET Core packages on RHEL 8
With RHEL 8, .NET Core is included in the AppStream repositories, which are enabled by default on RHEL 8 systems. At least two versions of .NET Core are already available on RHEL 8, and more will be added as they are released.
Multiple versions of .NET Core can be installed in parallel (side-by-side). You can pick and choose which components of .NET Core (SDK, Runtime) you need and install just those. Installing a component will install all of its dependencies. For example, installing a .NET Core SDK will also install the corresponding .NET Core Runtime as well as any other additional SDK dependencies.
You can install a specific version of the .NET Core SDK:
dnf install dotnet-sdk-2.1
Or
dnf install dotnet-sdk-3.0
In general, you can install the .NET Core SDK version x.y
using:
dnf install dotnet-sdk-x.y
If you are not interested in developing .NET Core applications, rather just running them, you can skip the SDK and only install a specific version of the .NET Core Runtime. For example:
dnf install dotnet-runtime-2.1
Or
dnf install dotnet-runtime-3.0
Generally, you can install the .NET Core Runtime version x.y
using:
dnf install dotnet-runtime-x.y
Starting with .NET Core 3.0, you also can install the ASP.NET Core Runtime, which lets you run framework-dependent ASP.NET Core applications:
dnf install aspnetcore-runtime-3.0
Running .NET Core
Once you have installed .NET Core on RHEL 8, you can simply start using the dotnet
command. To make sure .NET Core is installed, try:
dotnet --info
That should show more information about .NET Core, including the specific components that are installed:
.NET Core SDK (reflecting any global.json): Version: 3.0.100 Commit: 04339c3a26 Runtime Environment: OS Name: rhel OS Version: 8 OS Platform: Linux RID: rhel.8-x64 Base Path: /usr/lib64/dotnet/sdk/3.0.100/ Host (useful for support): Version: 3.0.0 Commit: 7d57652f33 .NET Core SDKs installed: 2.1.509 [/usr/lib64/dotnet/sdk] 3.0.100 [/usr/lib64/dotnet/sdk] .NET Core runtimes installed: Microsoft.AspNetCore.App 3.0.0 [/usr/lib64/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.13 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
We can now use .NET Core SDK to create, build, publish, and run a simple Hello World application:
$ mkdir HelloWorld $ cd HelloWorld/ $ dotnet new console Welcome to .NET Core 3.0! --------------------- SDK Version: 3.0.100 ---------------- Explore documentation: https://aka.ms/dotnet-docs Report issues and find source on GitHub: https://github.com/dotnet/core Find out what's new: https://aka.ms/dotnet-whats-new Learn about the installed HTTPS developer cert: https://aka.ms/aspnet-core-https Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs Write your first app: https://aka.ms/first-net-core-app -------------------------------------------------------------------------------------- Getting ready... The template "Console Application" was created successfully. Processing post-creation actions... Running 'dotnet restore' on /HelloWorld/HelloWorld.csproj... Restore completed in 50.91 ms for /HelloWorld/HelloWorld.csproj. Restore succeeded. $ dotnet publish --configuration Release --runtime rhel.8-x64 --self-contained false Microsoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core Copyright (C) Microsoft Corporation. All rights reserved. Restore completed in 49.95 ms for /HelloWorld/HelloWorld.csproj. HelloWorld -> /HelloWorld/bin/Release/netcoreapp3.0/rhel.8-x64/HelloWorld.dll HelloWorld -> /HelloWorld/bin/Release/netcoreapp3.0/rhel.8-x64/publish/ $ dotnet bin/Release/netcoreapp3.0/rhel.8-x64/publish/HelloWorld.dll Hello World!
See the .NET Core documentation for more information, including references, samples, and tutorials.
Using .NET Core RHEL 8-based container images
With Red Hat Enterprise Linux 8, .NET Core also is available in RHEL 8-based container images called Universal Base Image. You can use the container images to develop and deploy your .NET Core applications in containerized environments, such as OpenShift and Kubernetes.
To get a .NET Core 2.1 SDK container, use:
registry.access.redhat.com/ubi8/dotnet-21
To get a .NET Core 3.0 SDK container, use:
registry.access.redhat.com/ubi8/dotnet-30
To get a .NET Core 2.1 runtime container, use:
registry.access.redhat.com/ubi8/dotnet-21-runtime
To get a .NET Core 3.0 runtime container, use:
registry.access.redhat.com/ubi8/dotnet-30-runtime
Running .NET Core containers
You can use the .NET Core RHEL 8-based containers in your container pipelines. You can use it for deployment to cloud environments. You can also use it for building source-to-image (also called s2i) applications.
As an example, let’s create, build, and run a Hello World-style application in a container. Create a Dockerfile
that contains the following:
FROM registry.access.redhat.com/ubi8/dotnet-30 RUN dotnet --info && \ dotnet new console -o HelloWorld && \ cd HelloWorld && \ dotnet publish --configuration Release ENTRYPOINT dotnet HelloWorld/bin/Release/netcoreapp3.0/publish/HelloWorld.dll
You can build and run this using podman or docker commands:
$ podman build -t hello . STEP 1: FROM registry.access.redhat.com/ubi8/dotnet-30 Getting image source signatures Copying blob d4639cd2c710 done Copying blob 1fa946e8e839 done Copying blob 340ff6d7f58c done Copying blob 0e8ea260d026 done Copying config ca818f6208 done Writing manifest to image destination Storing signatures STEP 2: RUN dotnet --info && dotnet new console -o HelloWorld && cd HelloWorld && dotnet publish --configuration Release .NET Core SDK (reflecting any global.json): Version: 3.0.100 Commit: 04339c3a26 Runtime Environment: OS Name: rhel OS Version: 8 OS Platform: Linux RID: rhel.8-x64 Base Path: /usr/lib64/dotnet/sdk/3.0.100/ Host (useful for support): Version: 3.0.0 Commit: 7d57652f33 .NET Core SDKs installed: 3.0.100 [/usr/lib64/dotnet/sdk] .NET Core runtimes installed: Microsoft.AspNetCore.App 3.0.0 [/usr/lib64/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.0.0 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download Getting ready... The template "Console Application" was created successfully. Processing post-creation actions... Running 'dotnet restore' on HelloWorld/HelloWorld.csproj... Restore completed in 51.76 ms for /opt/app-root/src/HelloWorld/HelloWorld.csproj. Restore succeeded. Microsoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core Copyright (C) Microsoft Corporation. All rights reserved. Restore completed in 14.11 ms for /opt/app-root/src/HelloWorld/HelloWorld.csproj. HelloWorld -> /opt/app-root/src/HelloWorld/bin/Release/netcoreapp3.0/HelloWorld.dll HelloWorld -> /opt/app-root/src/HelloWorld/bin/Release/netcoreapp3.0/publish/ 164ce90cf7892154ab5a6a00f8d5f890dd26ffaabe0b6dd58c4005603fe325d4 STEP 3: ENTRYPOINT dotnet HelloWorld/bin/Release/netcoreapp3.0/publish/HelloWorld.dll STEP 4: COMMIT hello 1bd4ceedbcec15de4d99ee79ad5860d6f97031da1f4db32f7d408274262f8bec $ podman run -it hello Hello World!
Support and lifecycle
In general, .NET Core on Red Hat Enterprise Linux tries to follow the .NET Core lifecycle established by Microsoft. To learn more about .NET Core lifecycle on RHEL 8, visit the Red Hat Enterprise Linux 8 Application Streams Life Cycle page.
If you run into any errors, please report it as a bug in Bugzilla.
Last updated: January 13, 2022