Chapter 1. Using .NET Core 3.0 on Red Hat Enterprise Linux 8
This Getting Started Guide for RHEL 8 describes how to install .NET Core 3.0 on Red Hat Enterprise Linux (RHEL). See Red Hat Enterprise Linux documentation for more information about RHEL 8.
1.1. Install .NET Core Copy linkLink copied to clipboard!
.NET Core 3.0 is included in the AppStream repositories for RHEL 8. The AppStream repositories are enabled by default on RHEL 8 systems.
Install .NET Core 3.0 and all of its dependencies:
sudo yum install dotnet-sdk-3.0 -y
$ sudo yum install dotnet-sdk-3.0 -yCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the following command to verify the installation:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.2. Create an Application Copy linkLink copied to clipboard!
Create a new Console application in a directory called
hello-world:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the project:
cd hello-world dotnet run Hello World!
$ cd hello-world $ dotnet run Hello World!Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.3. Publish Applications Copy linkLink copied to clipboard!
The .NET Core 3.0 applications can be published to use a shared system-wide version of .NET Core or to include .NET Core. These two deployment types are called framework-dependent deployment (FDD) and self-contained deployment (SCD), respectively.
For RHEL, we recommend publishing by FDD. This method ensures the application is using an up-to-date version of .NET Core, built by Red Hat, that includes a specific set of native dependencies. On the other hand, SCD uses a runtime built by Microsoft.
Use the following command to publish a framework-dependent application.
dotnet publish -f netcoreapp3.0 -c Release
$ dotnet publish -f netcoreapp3.0 -c ReleaseCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: If the application is only for RHEL, trim out the dependencies needed for other platforms with these commands.
dotnet restore -r rhel.8-x64 dotnet publish -f netcoreapp3.0 -c Release -r rhel.8-x64 --self-contained false
$ dotnet restore -r rhel.8-x64 $ dotnet publish -f netcoreapp3.0 -c Release -r rhel.8-x64 --self-contained falseCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.4. Run Applications on Linux Containers Copy linkLink copied to clipboard!
This section shows how to use the ubi8/dotnet-30-runtime image to run a precompiled application inside a Linux container.
Create a new mvc project in a directory named
mvc_runtime_example.dotnet new mvc -o mvc_runtime_example cd mvc_runtime_example
$ dotnet new mvc -o mvc_runtime_example $ cd mvc_runtime_exampleCopy to Clipboard Copied! Toggle word wrap Toggle overflow Publish the project.
dotnet publish -f netcoreapp3.0 -c Release
$ dotnet publish -f netcoreapp3.0 -c ReleaseCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
Dockerfile.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build your image.
podman build -t dotnet-30-runtime-example .
$ podman build -t dotnet-30-runtime-example .Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run your image.
podman run -d -p8080:8080 dotnet-30-runtime-example
$ podman run -d -p8080:8080 dotnet-30-runtime-exampleCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
View the result in a browser:
http://127.0.0.1:8080.