Skip to main content

Prerequisites

These steps work on Windows, macOS, or Linux. Adjust commands for your OS and editor of choice.

1. Enable Kubernetes in Docker Desktop

Open Docker Desktop, go to Settings > Kubernetes, then:
  1. Check Enable Kubernetes.
  2. Click Apply & Restart to bootstrap a single-node cluster.
The image shows a computer desktop with Docker Desktop settings open, specifically the Kubernetes configuration section. The left side of the screen displays desktop icons for Recycle Bin, Docker Desktop, and JetBrains Rider.

2. Verify Your .NET 6 Installation

Run:
Make sure .NET 6.x appears in the list. Earlier versions will not compile this sample.

3. Create the ASP.NET Core Web App

  1. Launch JetBrains Rider and click New Solution.
  2. Select ASP.NET Core Web Application. Name the project KodeKloudApp and set the solution folder.
  3. Choose the Web App template.
  4. Enable Docker support and select Linux containers.
The image shows a computer screen with JetBrains Rider open, displaying the "New Solution" window for creating an ASP.NET Core Web Application. The desktop background features a blue abstract design.

4. Modify the Page Model

Open Pages/Index.cshtml.cs and inject IConfiguration to read a custom message:

5. Configure appsettings.json

Add the "Message" key to the JSON file:

6. Update the Razor Page

In Pages/Index.cshtml, render the message:

7. Run and Validate

Start the application:
Open your browser to the displayed URL (e.g., https://localhost:5001). You should see Hello World.
Stop the app, update "Message" in appsettings.json to "Hello World changed", save, then restart and refresh:
The image shows a web page titled "KodeKloudApp" with a welcome message and a highlighted text saying "Message: Hello World changed!!!" It includes links to "Home" and "Privacy" at the top.

8. Multi-Stage Dockerfile

Use this Dockerfile to build and run with a minimal runtime image:

9. Build and Push the Docker Image

From your project root:
Optionally, pull the sample image:

Watch Video