3. Create New Project and Dockerize the Project - AnbuMani27/Kubernetes-with-Helm-Charts GitHub 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
-
Open Visual Studio and Click New => Project => In the dialog selects ASP.NET Core Web API and click Next
-
Next, Enter appropriate Project Name, Solution name and Location, then click Next.
-
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.
-
After the Project creation, Run the App with IIS Express then see the below output.
Process:2 Build Docker Image for Web API.
-
Open the Commend Prompt, PowerShell or visual studio code (if not already opened) and navigate to the project folder.
-
To build the Web API and run the below command.
docker build -t kubehelmapi -f "KubeHelmAPI/DockerFile" .
-
Next, Verify your Docker Image is created via below command.
docker images
-
Run the Web API Docker Image via below command.
docker run -t -p 8080:80 kubehelmapi:latest
-
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
-
Create an account in docker hub if not exist via URL, else skip this step,
-
Open PowerShell
-
Enter the Below command to Authenticate docker Login,
docker login
NOTE: Change your docker registry name before executing command on Step 4 & 5.
-
Run the below command to tag the Web API with docker registry.
docker tag kubehelmapi <your-docker-registry-name>/kubehelmapi
-
Push the Tagged Image to docker hub via below command,
docker push <your-docker-registry-name>/kubehelmapi