This is a cache of https://docs.openshift.com/container-platform/3.6/using_images/s2i_images/dot_net_core.html. It is a snapshot of the page at 2024-11-22T03:52:21.461+0000.
.NET Core - Source-to-Image (<strong>s2i</strong>) | Using Images | OpenShift Container Platform 3.6
×

Benefits of Using .NET Core

.NET Core is a general purpose development platform featuring automatic memory management and modern programming languages. It allows users to build high-quality applications efficiently. .NET Core is available on Red Hat Enterprise Linux (RHEL 7) and OpenShift Container Platform via certified containers. .NET Core offers:

  • The ability to follow a microservices-based approach, where some components are built with .NET and others with Java, but all can run on a common, supported platform in Red Hat Enterprise Linux and OpenShift Container Platform.

  • The capacity to more easily develop new .NET Core workloads on Windows; customers are able to deploy and run on either Red Hat Enterprise Linux or Windows Server.

  • A heterogeneous data center, where the underlying infrastructure is capable of running .NET applications without having to rely solely on Windows Server.

  • Access to many of the popular development frameworks such as .NET, Java, Ruby, and Python from within OpenShift Container Platform.

Supported Versions

  • .NET Core version 2.2

  • .NET Core version 2.1

  • .NET Core version 1.1

  • .NET Core version 1.0

  • Supported on Red Hat Enterprise Linux (RHEL) 7 and OpenShift Container Platform versions 3.3 and later

For release details related to .NET Core version 2.2, see Release Notes for Containers.

For release details related to .NET Core version 2.1, see Release Notes for Containers.

Versions 1.1 and 1.0 (rh-dotnetcore11 and rh-dotnetcore10) ship with the project.json build system (1.0.0-preview2 SDK). See the Known Issues chapter in the version 1.1 Release Notes for details on installing this SDK on a non-RHEL system.

Images

The RHEL 7 images are available through the Red Hat Registry:

$ docker pull registry.access.redhat.com/dotnet/dotnet-22-rhel7
$ docker pull registry.access.redhat.com/dotnet/dotnet-21-rhel7
$ docker pull registry.access.redhat.com/dotnet/dotnetcore-11-rhel7
$ docker pull registry.access.redhat.com/dotnet/dotnetcore-10-rhel7

Image stream definitions for the .NET Core on RHEL s2i image are now added during OpenShift Container Platform installations.

Build Process

s2i produces ready-to-run images by injecting source code into a container and letting the container prepare that source code for execution. It performs the following steps:

  1. Starts a container from the builder image.

  2. Downloads the application source.

  3. Streams the scripts and application sources into the builder image container.

  4. Runs the assemble script (from the builder image).

  5. Saves the final image.

See s2i Build Process for a detailed overview of the build process.

Configuration

The .NET Core images support several environment variables, which you can set to control the build behavior of your .NET Core application.

You must set environment variables that control build behavior in the s2i build configuration or in the .s2i/environment file to make them available to the build steps.

Table 1. NET Core Environment Variables
Variable Name Description Default

DOTNET_STARTUP_PROJECT

Used to select the project to run. This must be the folder in the source repository containing project.json.

.

DOTNET_ASSEMBLY_NAME

Used to select the assembly to run. This must not include the .dll extension. Set this to the output assembly name specified in project.json (name, buildOptions/outputName). For project.json, the assembly name defaults to the project.json parent folder. When project.json is at the context-dir, the parent folder name will be src. So, by default, this generates a src.dll assembly. Setting DOTNET_ASSEMBLY_NAME will cause:

  • The assembly to be <DOTNET_ASSEMBLY_NAME>.dll

  • The application sources to be in subfolder DOTNET_ASSEMBLY_NAME in the deployed container.

The name of the DOTNET_STARTUP_PROJECT folder.

DOTNET_RESTORE_SOURCES

Used to specify the space-separated list of NuGet package sources used during the restore operation. This overrides all of the sources specified in the NuGet.config file.

Unset

DOTNET_NPM_TOOLS

Used to specify a list of NPM packages to install before building the application.

Unset

DOTNET_TEST_PROJECTS

Used to specify the space-separated list of test projects to run. This must be folders containing project.json. dotnet test is invoked for each folder.

Unset

DOTNET_CONFIGURATION

Used to run the application in Debug or Release mode. This value should be either Release or Debug.

Release

ASPNETCORE_URLS

This variable is set to http://*:8080 to configure ASP.NET Core to use the port exposed by the image. It is not recommended to change this.

http://*:8080

DOTNET_RM_SRC

When set to true, the source code is not included in the image.

DOTNET_SSL_DIRS

Used to specify a list of folders and files with additional SSL certificates to trust. The certificates are trusted by each process that runs during the build and all processes that run in the image after the build, including the application that was built. The items can be absolute paths starting with / or paths in the source repository (for example, certificates).

DOTNET_RESTORE_DISABLE_PARALLEL

When set to true, disables restoring multiple projects in parallel. This reduces restore timeout errors when the build container is running with low CPU limits.

false

DOTNET_INCREMENTAL

When set to true, the NuGet packages are kept so they can be re-used for an incremental build.

false

DOTNET_PACK

When set to true, creates a tar.gz file at /opt/app-root/app.tar.gz that contains the published application.

Quickly Deploying Applications from .NET Core Source

The .NET image stream must first be installed. If you ran a standard installation, the image stream will be present.

An image can be used to build an application by running oc new-app against a sample repository:

$ oc new-app registry.access.redhat.com/dotnet/dotnet-22-rhel7~https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnetcore-2.2 --context-dir=app
$ oc new-app registry.access.redhat.com/dotnet/dotnet-21-rhel7~https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnetcore-2.1 --context-dir=app
$ oc new-app registry.access.redhat.com/dotnet/dotnetcore-11-rhel7~https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnetcore-1.1 --context-dir=app
$ oc new-app registry.access.redhat.com/dotnet/dotnetcore-10-rhel7~https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnetcore-1.0 --context-dir=app

The oc new-app command can detect .NET Core source starting in OpenShift Container Platform 3.3.

.NET Core Templates

The .NET image templates and the .NET images streams must first be installed. If you ran a standard installation, the templates and image streams will be present. This can be checked with:

$ (oc get -n openshift templates; oc get -n openshift is) | grep dotnet

OpenShift Container Platform includes templates for the .NET Core images to help easily deploy a sample application.

The .NET Core sample application running on dotnet/dotnet-22-rhel7 can be deployed with:

$ oc new-app --template dotnet-example -p DOTNET_IMAGE_STREAM_TAG=dotnet:2.2 -p SOURCE_REPOSITORY_REF=dotnetcore-2.2

The .NET Core sample application running on dotnet/dotnetcore-10-rhel7 can be deployed with:

$ oc new-app --template dotnet-example

The .NET Core MusicStore application using PostgreSQL as database can be deployed with:

$ oc new-app --template=dotnet-pgsql-persistent