3. Create New Project and Dockerize the Project - AnbuMani27/Kubernetes-with-Helm-Charts Wiki

Here, we are going to create the ASP.NET Core Web API with default template and Add Docker Support to the project.

If you have an existing projects, Skip the steps 1,2 in these Process:1 for Create New Web API.

Process:1 Create ASP.NET Core Web API in .NET Core 3.1

  1. Open Visual Studio and Click New => Project => In the dialog selects ASP.NET Core Web API and click Next


  2. Next, Enter appropriate Project Name, Solution name and Location, then click Next.


  3. Select your Target Framework, then Enable Docker and select Linux Container then click Create.

    NOTE: If you enable Docker, file will automatically generate in your project else you need to initiate manually


    Manually Adding the Docker

    Step 1.


    Step 2.


  4. After the Project creation, Run the App with IIS Express then see the below output.


Process:2 Build Docker Image for Web API.

  1. Open the Commend Prompt, PowerShell or visual studio code (if not already opened) and navigate to the project folder.

  2. To build the Web API and run the below command.

    docker build -t kubehelmapi -f "KubeHelmAPI/DockerFile" .


  3. Next, Verify your Docker Image is created via below command.

    docker images


  4. Run the Web API Docker Image via below command.

    docker run -t -p 8080:80 kubehelmapi:latest


  5. To Validate API Open Either Browser and enter http://localhost:8080/weatherforecast to view the below result,


Process:3 Push Web API Docker Image to Docker Hub

  1. Create an account in docker hub if not exist via URL, else skip this step,

  2. Open PowerShell

  3. Enter the Below command to Authenticate docker Login,

    docker login

NOTE: Change your docker registry name before executing command on Step 4 & 5.

  1. Run the below command to tag the Web API with docker registry.

    docker tag kubehelmapi <your-docker-registry-name>/kubehelmapi

  2. Push the Tagged Image to docker hub via below command,

    docker push <your-docker-registry-name>/kubehelmapi