Azure Container Registry for Building and Deploying .NET Core Apps

As 1st step create a .NET Core console application, "TImeStamp", to display current UTC date time.

Create Azure Container Registry  -

Azure Container Registry aka ACR can be used to store your build repositories. You should create an Azure Container Registry with all default settings as below. Please notice that my ACR name is "mytestingacr" and currently there isn't any repositories in it.

Enable Docker to "TImeStamp" App -

I used VS 2019 to add Docker support to my sample .NET Core application. Its just a right-click on project as below.
Above step will be adding a docker file as below, which includes all commands to build the container. These commands will be executed by ACR, not locally.

Tool to Execute CLI Commands -

Azure CLI commands can be used to communicate to Azure from your local machine. This time I used "Git Bash" windows as a tool to execute Azure CLI commands. You need to go to the root folder of the sample application. Then follow below steps to enable Azure CLI in Git Bash.
  1. Go C:\Program Files\Git\etc\profile.d
  2. Edit, to add a new alias for az as, alias az='az.cmd'
You are now ready to execute Azure CLI commands. Below are the steps 
    1. Build "TImeStamp" App as a Container - Use below CLI command to upload your code and build it inside ACR
                   az acr build -t jaishdemo/timestamp -r mytestingacr -f Dockerfile .
                  This is telling that build in acr with a tag "jaishdemo/timestamp", which will be the repository name inside ACR. I also mentioned my ACR name to                    argument "-r". Last 2 arguments are docker file name to be used for build and also the context to be considered. My context is the root folder of the sample                   application and so just mentioned as "." . Please notice the status showing from creating a .TAR file and uploading it to ACR and queue for build etc... below.
After successful ACR build, you see below last set of status through command window. Please notice image repository details mentioned there as "jaishdemo/timestamp".
 2. Verify the Build in ACR - Now you should notice your repository inside ACR as below.
 3.  Deploy the Build to an Azure Container Instance(ACI) -  Azure Container Instance is used to deploy your container builds and run it in there. To deploy the build, you need your existing ACR credentials, which is available from Access keys tab of the Azure portal.
Run below command to deploy the build to an ACI
az container create -n timestamp -g dxceagapp --image --repository-username <<username>> --repository-password <<password>>
The command is asking to create a container "timestamp" using the build in my ACR. I mentioned my resource group "dxceagapp" as well. Here repository username and password to be taken from above mentioned diagram. Please make sure below status for a successful deployment.
4. Run the Deployed Build inside Azure Container Instance(ACI)
Now you need to check and verify that your Container Instance has "timestamp" app in it and it's running to give the expected out put. Please verify the Container Instance presence in Azue portal as below with the name "timestamp". Under Containers tab, you need to click the "Connect" section as below.
You need to give a startup command as "dotnet run", which is the .NET Core command to run the application, and then click Connect button. Ref. below diagram.
Wait till the connection has opened and then closed. The below window will tell you this.
Now click the "Logs" tab and see the output from the App as expected. It has displayed the UTC time of the moment. Ref. below diagram.
So you haven't a dependency with local container engine for building you containers. Azure Container Registry will do it for you. This is extremely helpful during scenarios like you got a new system or your existing system just formatted etc. Hope you have enjoyed this article and I will come with more on Azure later.