Enable .NET channel

In order to install .NET Core from Red Hat on RHEL, you first need to register using the Red Hat Subscription Manager. If this has not been done on your system, or if you are unsure, see the Red Hat Getting Started Guide.

Install the .NET SDK

After registering with the Subscription Manager and enabling the .NET Core channel, you are ready to install and enable the .NET SDK.

In your terminal, run the following commands:

Terminal

yum install rh-dotnet22 -yscl enable rh-dotnet22 bash

Register Microsoft key and feed

Before installing .NET, you'll need to register the Microsoft key, register the product repository, and install required dependencies. This only needs to be done once per machine.

Check everything installed correctly

Once you've installed, open a new command prompt and run the following command:

Once you've installed, open a new terminal and run the following command:

Command prompt

dotnet

If the command runs, printing out information about how to use dotnet, you're good to go.

If you receive a 'dotnet' is not recognized as an internal or external command error, make sure you opened a new command prompt. If you can't resolve the issue, use the I ran into an issue button to get help fixing the problem.

Create your service

Create an app

In your command prompt, run the following commands:

In your terminal, run the following commands:

Command prompt

dotnet new webapi -o myMicroservice --no-httpscd myMicroservice

The dotnet command creates a new application of type webapi (that's a REST API endpoint).

The -o parameter creates a directory named myMicroservice where your app is stored.

The --no-https flag creates an app that will run without an HTTPS certificate, to keep things simple for deployment.

The cd myMicroService command puts you into the newly created app directory.

The generated code

Several files were created in the myNewMicroService directory, to give you a simple service that is ready to run.

Check that Docker is ready to use

Once you've installed, open a new command prompt and run the following command:

Once you've installed, open a new terminal and run the following command:

Command prompt

docker --version

If the command runs, displaying some version information, then Docker is successfully installed.

Add Docker metadata

To run with Docker Image you need a Dockerfile — a text file that contains instructions for how to build your app as a Docker image. A docker image contains everything needed to run your app as a Docker container.

Return to app directory

Since you opened a new command prompt in the previous step, you'll need to return to the directory you created your service in.

Since you opened a new terminal in the previous step, you'll need to return to the directory you created your service in.

Command prompt

cd myMicroservice

Add a DockerFile

Create a file called Dockerfile with the following content in a text editor: