Containerizing Microservices (.NET Core Application) Using Azure


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 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 "" to build a local image using docker.

Azure Container Registry

2. Open Azure Portal and Go to Create Resource -> Containers -> Container Registry.
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.
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. 

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  
6. The next step is to log in to the Azure container registry using loginserver/imagename, username, and password.
  1. dokcer login loginserver/imagename( -u username -p password  
e.g. docker login -u trainingservice1 -p lddH+ejcVXQf81nNWP3C9bTOA
After successful login, push the image into Azure repository using docker push.
  1. docker push  
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. 

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.
9. Once your container instance is ready, go to overview and copy the public IP address to get your new service URL.
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, where trainingservice is the controller name of my core application created in the previous article. Finally, this Azure service can be deployed/consumed by any of your front-end applications.


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