Containerizing Microservices (.NET Core Application) Using Azure

Introduction

 
In this article, I am going to talk about deploying of microservices (.NET Core) using Azure container registry and container instance. And the service can be consumed by any front-end application like HTML, etc., I will be demonstrating in a step-by-step manner how to deploy ASP.NET Core application docker image into Azure and creating container instance from it.
 

Create local asp.net core image using docker

 
1. Download the attached code and run the below command to execute the docker file to build new image docker "build -t yourImagename:tagname .", you can either follow my article " https://www.c-sharpcorner.com/blogs/deploying-netcore-application-to-docker-container" to build a local image using docker.
 

Azure Container Registry

 
2. Open Azure Portal and Go to Create Resource -> Containers -> Container Registry.
 
image1 
 
3. Create new Container Registry, enable admin user to generate userid and password of this registry, this information will be used later when you push the local docker image into Azure. you can also enable admin user later in case you forget to enable when you create a registry.
 
imaghe2
 
4. Once the Azure Registry is created successfully, keep Login server, Admin user and password details with you to push your local image into this Azure registry. 
 
image3 
 

Tag and push the local image into the Azure Registry

 
4. Let's come back to the host machine where your local image was ready. Open power shell and execute 'docker images' to check your local image.
 
5. Tag your local image with a new name "loginservername/imagename" using docker command "docker tag localimage newimageName", verify new tagged image again with the same command docker images.
 
  1. docker tag trainingservice1:v2 trainingservice1.azurecr.io/trainingservice  
 
image4 
 
6. The next step is to log in to the Azure container registry using loginserver/imagename, username, and password.
 
  1. dokcer login loginserver/imagename(......azureecr.io/imagename:tagname) -u username -p password  
 
e.g. docker login trainingservice1.azurecr.io/trainingservice -u trainingservice1 -p lddH+ejcVXQf81nNWP3C9bTOA
 
After successful login, push the image into Azure repository using docker push.
 
  1. docker push trainingservice1.azurecr.io/trainingservice  
 
image5 
 
7.  Once your local image is pushed to Azure container repository and it is part of the Azure registry which you created in step 2, that can also be verified under your registry-> Repositories
 
The final step is to create container instance using this image and consume it on any front-end application. 
 
image6 
 

Azure Container Instance

 
8. Create new resource i.e. Container Instance, go to Create Resource -> Containers -> Container Instance.
 
There are a few parameters to be taken care of while  creating new container instances, like Image type; i.e. private, as we are using the Azure repository, Image Name i.e. Loginserver/imagename and user name and password are the same which were used for login.
 
image7
 
9. Once your container instance is ready, go to overview and copy the public IP address to get your new service URL.
 
image8 
 
When we deployed this service into docker on a local machine, the service URL was generated as https://localhost:44382/TrainingService  and after deploying the same service into the Azure container the URL of service is https://40.81.250.164/trainingservice, where trainingservice is the controller name of my asp.net core application created in the previous article. Finally, this Azure service can be deployed/consumed by any of your front-end applications.
 

Summary

 
Here, we learned to deploy Microservices developed in .NET Core language into Azure container (using Azure container registry) from the local docker image.