Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Building .NET Core container images using S2I

<p>&nbsp;</p> <quillbot-extension-portal></quillbot-extension-portal>

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

    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

    • SQL Server HA on RHEL: Meet Pacemaker HA Agent v2 (tech preview)

    • Deploy with confidence: Continuous integration and continuous delivery for agentic AI

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    What’s up next?

     

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.