A Simple Guide for Containerization of ASP.NET E-Commerce Application

May 20, 2022 | Comments(1) |
TABLE OF CONTENT
1. Introduction
2. Technologies Leveraged
3. Prerequisites
4. Preparing MongoDB Docker Image
5. Preparing Grandnode Docker Image
6. Running the E-Commerce Application Locally
7. Creating Container Registry for Application Container Images
8. Pushing Images to The Registry
10. Conclusion
11. About CloudThat
12. FAQs

 

Introduction

Containerization primarily offers us the benefit of swift deployment, scaling, and patching of our applications. Moreover, an existing .NET application can be migrated to Windows containers without modifying the code most of the time. An appropriate docker base image needs to be chosen, and a Dockerfile needs to be prepared for containerizing your application. Keeping your application containerized in container registries like DockerHub, and Azure Container Registry offers portability and agility. They offer the ability to spin up new custom versions of our application easier and faster than virtual machines.

Technologies Leveraged

  • Docker
  • Grandnode
  • MongoDB
  • Azure Container Registry

Prerequisites

  1. Azure account
  2. GitHub account
  3. Azure CLI
  4. Windows Server 2019 / Windows 10 (If you use a different operating system, use the corresponding source code and make required changes to the entire setup.)
  5. Docker

Preparing MongoDB Docker Image

 

1. Clone the GitHub repo at “https://github.com/aneez004/mongo-windows.git”. Then, switch to the git folder.

2. Modify the mongodbuser.ps1 file

3. Add a database username and password of your choice, or keep the defaults. Here we add the user “grandadmin” with a password “grand” to the database admin. In the Dockerfile, we are using the mongo windows image as the base image, and we copy over the PowerShell script to create the db user.

4. Build and tag the docker image with a preferred tag name.

docker build -t <image name:tag>

 

1. Clone the Github repo at “https://github.com/aneez004/grandnode2.git”. Then, navigate to the “grandnode2” folder.

2. Verify the Dockerfile.

3. Build and tag the image.

docker build -t <image name:tag>

 

Running the E-Commerce Application Locally

1. Run the mongodb docker container.

docker run -d -p 27017:27017 –name mongodb aneez004/mongo:grandnodev1

2. Run the grandnode docker container by linking to the mongodb container.

docker run -d -p 8080:80 –link mongodb:mongo –name grandnode aneez004/grandnode:v1

3. Verify both containers are up and running

docker ps

4. Access the application from a browser at http://localhost:8080

5. Enter company information. Under ‘Store Information,’ provide the admin email username and password.

6. Under ‘Database Information,’ enter the following details:

a. MongoDB Server Name: MongoDB (the exact name you provide using –name option during docker run)

b. Database name: admin

c. Username: grandadmin (replace with what you have given in the mongodbuser.ps1 file)

d. Password: grand (replace with what you have given in the mongodbuser.ps1 file)

Click on Install.

7. Restart the grandnode container.

8. Access the application at http://localhost:8080

Access the admin page to modify your E-Commerce site. Enter the admin username and password provided during grandnode installation.

 

Creating Container Registry for Application Container Images

1. Log in to the Azure portal. If you don’t have an account, create a free account at https://azure.microsoft.com/en-us/free/ 

2. Search and select ‘Container Registries’

3. Click on Create container registry

4. Please select your subscription, create a new resource group and select it

5. Enter a unique ‘Registry Name.’ Note down this name for future requirements.

6. Accept default values for the remaining settings. Then select Review + create. After reviewing the settings, select Create.

Note down the registry name and login server.

Pushing Images to The Registry

  1. Install chocolatey (if not installed) using instructions from the link https://chocolatey.org/install.
  2. Install Azure CLI using the following command.

choco install -y azure-cli

3. Log into your Azure account using Azure CLI (Command-Line Interface) using the following command:

az login

4. Enter your credentials from the browser pop up window

5. Log in to the Azure Container registry before pushing container images to the registry.

az acr login –name <registry name>

6. Tag the docker images built in the previous sections in the azure container registry name format. Replace the required values.

docker ps

docker tag <grandnode image name:tag> <registryname>.azurecr.io/grandnode:v1

docker tag <mongo image name:tag> <registryname>.azurecr.io/mongo:v1

 

7. Push the application container images to the Azure container registry.

docker push <registryname>.azurecr.io/grandnode:v1

docker push <registryname>.azurecr.io/mongo:v1

8. Verify that the images are pushed

az acr repository list –name <registry name>

 

Conclusion

Migration of Windows workloads to micro-service-based architecture is gaining acceptance as it offers increased flexibility, security, high availability, and portability for their applications. Microsoft .NET applications can now be easily containerized and deployed on existing managed Kubernetes clusters like Amazon EKS or Azure AKS by adding windows worker nodes to the existing cluster with Linux nodes.

Here is a Step By Step Procedure for AWS App Mesh Integration With EKS

https://blog.cloudthat.com/step-by-step-procedure-to-aws-app-mesh-integration-with-eks/?utm_source=blog-website&utm-medium=text-link&utm_campaign=step-by-step-procedure-to-aws-app-mesh-integration-with-eks

About CloudThat

CloudThat is the official AWS Advanced Consulting Partner, Microsoft Gold Partner, and Google Cloud Partner, helping people develop knowledge on the cloud and help their businesses aim for higher goals using best in industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.

Feel free to drop a comment or any queries that you have regarding AWS services, Kubernetes Engine, or consulting requirements and we will get back to you quickly. To get started, go through our Expert Advisory page and Managed Services Package that is CloudThat’s offerings.

FAQs

   1. What are the guidelines for selecting a windows base image for containerization?

a. Use ‘Windows server core’ if your application requires a complete .NET framework.

b. Use ‘Nano Server’ if building an application based on the .NET core.

c. If your application requires more dependencies and core windows libraries, use the’ Windows’ image.

    2. How to achieve High Availability with MongoDB?

a. Unlike relational databases, MongoDB is built on a distributed systems architecture, enabling us to scale out the database across multiple instances –        which can be one region or spread globally across multiple regions.

b. MongoDB stores the data used within the application and queries the data with a modern query language. Schema is flexible, enabling developers to integrate new functionality continuously.


One Response to “A Simple Guide for Containerization of ASP.NET E-Commerce Application”

Leave a Reply