Chapter 5. Running .NET 6.0 applications in containers

download PDF

Use the ubi8/dotnet-60-runtime image to run a precompiled application inside a Linux container.


  • Preconfigured containers.

    The following example uses podman.


  1. Optional: If you are in another project’s directory and do not wish to create a nested project, return to the parent directory of the project:

    # cd ..
  2. Create a new MVC project in a directory called mvc_runtime_example:

    $ dotnet new mvc --output mvc_runtime_example
  3. Publish the project:

    $ dotnet publish mvc_runtime_example -f net6.0 -c Release
  4. Create the Dockerfile:

    $ cat > Dockerfile <<EOF
    ADD bin/Release/net6.0/publish/ .
    CMD ["dotnet", "mvc_runtime_example.dll"]
  5. Build your image:

    $ podman build -t dotnet-60-runtime-example .
  6. Run your image:

    $ podman run -d -p8080:8080 dotnet-60-runtime-example

Verification steps

  • View the application running in the container:

    $ xdg-open
Red Hat logoGithubRedditYoutubeTwitter


Try, buy, & sell


About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.