Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Building .NET Core container images using S2I

 

December 13, 2018
Tom Deseyn
Related topics:
.NETCI/CDContainersKubernetes
Related products:
Red Hat OpenShift Container Platform

Share:

    Red Hat OpenShift implements .NET Core support via a source-to-image (S2I) builder. In this article, we’ll take a closer look at how you can use that builder directly. Using S2I, you can build .NET Core application images without having to write custom build scripts or Dockerfiles. This can be useful on your development machine or as part of a CI/CD pipeline.

    Containers for your builds

    Container images provide an efficient mechanism to deploy self-contained applications in a portable way across clouds and OS distributions.

    By building the application images themselves using a builder image, the application images can be built in a portable, reproducible way.

    S2I is a toolkit for building reproducible application images. S2I uses builder images to produce application images from source code or pre-compiled applications.

    application source/        +-------+
    prebuilt application  +--> |  s2i  | +-->  application image
                               +-------+
                                   ^
                            builder image
    

    On Fedora and Red Hat Enterprise Linux (RHEL), you can obtain S2I by installing the source-to-image package (yum install source-to-image). If you are using another OS, including Windows and macOS, you can download S2I from github.com/openshift/source-to-image/releases. You’ll also need to install docker and git, which are used by s2i.

    .NET Core builder images

    A builder image is available for each .NET Core version. These images are built from the Dockerfiles at github.com/redhat-developer/s2i-dotnetcore.

    For .NET Core 2.1, these images are available as follows:

    OS base Image Type Image Name
    RHEL 7 Runtime registry.redhat.io/dotnet/dotnet-21-runtime-rhel7:2.1
    RHEL 7 SDK registry.redhat.io/dotnet/dotnet-21-rhel7:2.1
    CentOS 7 Runtime registry.centos.org/dotnet/dotnet-21-runtime-centos7:latest
    CentOS 7 SDK registry.centos.org/dotnet/dotnet-21-centos7:latest

    If you are looking for a different .NET Core version, you can check the Red Hat Container Catalog or the CentOS Container Registry.

    To use the RHEL 7 images, you need a Red Hat subscription. For development, you can use the free development subscription. Use the docker login registry.redhat.io command to configure your credentials.

    Building images

    The sections below describe three ways you can build your images.

    Building an application image from a git repository

    As our first, example, we’ll build an application image named mywebapp for the ASP.NET Core application at github.com/redhat-developer/s2i-dotnetcore-ex.

    $ s2i build https://github.com/redhat-developer/s2i-dotnetcore-ex registry.redhat.io/dotnet/dotnet-21-rhel7:2.1 mywebapp -r dotnetcore-2.1 -e DOTNET_STARTUP_PROJECT=app -p always
    

    When we run this command, we’ll see s2i check out the sources and build the .NET Core application image. When the command finishes, we can run the newly created image:

    $ docker run --rm -p 8080:8080 mywebapp
    

    Let’s look at the parameters we’ve passed to the s2i command:

    Parameter Description
    registry.redhat.io/dotnet-21-rhel7:2.1 S2I builder image
    https://.../s2i-dotnetcore-ex The git repository
    -r dotnetcore-2.1 Branch in the repository
    -e DOTNET_STARTUP_PROJECT=app Folder in the repository that contains the application csproj file
    -p always Always pull the latest builder image

    The -e DOTNET_STARTUP_PROJECT is an environment variable passed to the S2I builder. The builder supports a number of environment variables that allow you to customize its behavior. See the environment variables documentation for a complete list.

    Building an application image from local sources

    The source parameter for the s2i command can also refer to a local folder that contains the source code. In the following example, we clone the repository locally and check out the appropriate branch into the s2i-dotnetcore-ex folder. Then we build from that local folder.

    $ git clone -b dotnetcore-2.1 https://github.com/redhat-developer/s2i-dotnetcore-ex
    $ s2i build s2i-dotnetcore-ex registry.redhat.io/dotnet/dotnet-21-rhel7:2.1 mywebapp -r dotnetcore-2.1 -e DOTNET_STARTUP_PROJECT=app -p always
    

    We can run the image using the same docker run command as before.

    Building an application image from a pre-built application

    The .NET Core builder can also be used to build an application image from a pre-built application.

    To explore this, we first publish the s2i-dotnetcore-ex application. To do that, you need to install a .NET SDK on your system (RHEL7/CentOS7, Fedora, other).

    $ git clone -b dotnetcore-2.1 https://github.com/redhat-developer/s2i-dotnetcore-ex
    $ cd s2i-dotnetcore-ex/app
    $ dotnet publish -c Release /p:MicrosoftNETPlatformLibrary=Microsoft.NETCore.App
    

    We are specifying the MicrosoftNETPlatformLibrary parameter to make the published application contain the ASP.NET Core shared framework assemblies. This is needed because the images don’t contain the shared framework.

    To create the image, we pass the publish folder as the source parameter of the s2i build command. We can use the SDK builder images like before, but since the application is already built, we can use the smaller runtime image instead.

    $ s2i build bin/Release/netcoreapp2.1/publish mywebapp registry.redhat.io/dotnet/dotnet-21-runtime-rhel7:2.1 -p always
    

    Conclusion

    In this article, you’ve learned how to create .NET Core application images using s2i. These images can be built directly from a git repository, local sources, or a pre-built application.

    Last updated: March 24, 2023

    Recent Posts

    • Run Qwen3-Next on vLLM with Red Hat AI: A step-by-step guide

    • How to implement observability with Python and Llama Stack

    • Deploy a lightweight AI model with AI Inference Server containerization

    • vLLM Semantic Router: Improving efficiency in AI reasoning

    • Declaratively assigning DNS records to virtual machines

    What’s up next?

     

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue