Docker Azure

Over the past few years, Docker has quickly evolved into a tool that every developer out there needs to master. For almost a year now, a Windows distribution of the tool has been made publicly available, making it possible for us to modernize existing .NET Web Applications by having them containerized with a single click; literally a single click. In late April of 2018, Microsoft also released Azure Container Instances (ACI), which allows enterprises to easily publish and consume containerized applications without having the requirement to handle all the piping behind managed container orchestrator platforms such as Azure Container Services (AKS), reducing both cost and complexity of solutions. In this article, we will take an existing .NET (4.6.2) Web Application, add Docker support to it, and have it run within an instance of Azure Container Instance. We will not be covering the basics of Docker and go into any advanced details regarding the processes that are running under the hood.

Step 1 – Install Docker for Windows

As a first step, we will need to make sure that the computer where we will be building our application has Docker for Windows installed on it. That distribution is available at:

On the install wizard screen, you will be asked to select whether or not you wish to have Docker run Windows containers. Make sure you check that box, otherwise Docker will only support running Linux containers by default.

Docker Installation

When the installation completes, you will be asked to logout in order for the changes to apply. Click on the Close and log out button.

Docker Installation Completed

Log back onto the server. If you didn’t already have the Hyper-V and Containers features activated on the box, you may be prompted to reboot. In that case, click on the Ok button, wait for the machine to reboot and log back in.

Reboot VM for Docker

When you log back onto the machine after Docker has been successfully installed, you will be prompted to connect with your Docker account. You can safely ignore this for this example by closing the window.

Add Docker Support to the Web Application

For the purpose of this blog article, I created a very simplistic ASP.NET web form project in Visual Studio that only consists of a login screen, and a few basic application pages.

Basic .NET Web Application

If we pay closer attention to the debugger control for the solution within Visual Studio, we can see that the debugger will launch an IIS Express process in the default browser, in my case Microsoft Edge.

IIS Express in Edge

What we want to achieve, is to add Docker support within our existing solution so that the default debugger process now compiles our solution within a Docker container image and uses Docker for Windows to execute it as a containerized web application. In order to do this, simply right click on your project within the Solution Explorer window, and select

Add Docker Support in Visual Studio

Doing this will automatically setup all the piping required in Visual Studio to run your application within a Docker container. Please note however, that by default Visual Studio will then initiate the download of the latest .NET Docker container image from the Docker gallery. This image can be several Gb big, so you might need to wait a few minutes before Visual Studio has all the components required to run your application within a container.

Pulling Docker image

While the image is being download, pay attention to what modifications were made to our project. While there are several modifications that happened from a Solution Explorer perspective (new project, docker file, etc.), the most important change to notice is that the debugger now default to a Docker process, which now allows you to run the application within a Docker container.

Docker debug in Visual Studio

Starting the debugger process will simply compile your web application as a Docker image running on top of the downloaded .NET image and run it within a container. You will notice that your container has been assigned its own unique IP address by default. We now have a Docker containerized Web Application running. It told you it was as simple as doing a right click!

Docker App

Publish the Image to Azure Container Registry

In order to be able to consume a Docker image in Azure Container Instance, it needs to be made accessible into what we call a Container Registry. Perhaps one of the most well-known one is Docker Hub, which allows you to publish your images into a private or public repository hosted at Docker. However, due to security and access control, organizations can choose to leverage Azure Container Registry (ACR) instead. ACR acts similar to the Docker Hub in that it is effectively a container imager repository where we can publish our images to.

The first thing we need to do, is create an actual ACR instance within our Azure portal.

Create Azure Container Registry

Provide a name to the ACR instance, choose a Resource group, and click on the Create button. It should take a few seconds for the instance to get created. Make sure you enable Admin User.

Create new Azure Container Registry Instance

Once your instance is ready, select it from the list by clicking on its name. In the left blade menu for your instance, select Access keys.

Azure Container Registry Access Keys

This section will provide us with a few bits of important information that will allow our local Docker instance to connect to ACR. From that screen, take good note of the Login server, Username and password values.

ACR Info

On your local machine, launch a command prompt. In my case I will be using the PowerShell console. From the console, type in the following command:

docker login nikacr.azurecr.io -u NikACR -p Ka6Hq3g6/AoW35uylRxRx+GBH4hPYFTW

If the information entered was correct, you should get a Login Succeeded message that appears. We have now connected our local Docker instance with Azure Container Registry: time to publish our image! In my case, when I compiled my Web Application in the previous step, it created a local image named niksuperapp. I actually have two images, one with the dev tag which is the debug build, and one tagged latest which is the release build from Visual Studio. To view the list of all images and figure out which one to use, you can type in the following command:

docker image ls

Docker Image LS

To initiate the publish operation of our image, we need to run the following command within our console:

docker tag niksuperapp nikacr.azurecr.io/niksuperapp
docker push nikacr.azurecr.io/niksuperapp

The first command tags the local image against our ACR repository, whereas the second line initiates the upload of the various layers that make up our image. It should take a few minutes for the upload process to complete depending on your connection speed.

Docker Push to Azure Container Registry

We are now ready to initiate an instance of the image we just uploaded into our Azure Registry Container instance.

Run in Azure Container Instance

In the Azure portal, navigate to the Azure Container Instance area. From the main blade, click on the Create container instances button.

New Azure Container Instance

In the new instance Basics blade, make sure you select Private as the Container instance type, provide the full name of the image including the ACR server name, and the connection information we’ve used in the previous step to connect to our ACR instance.

New Azure Container Instance - Basics

On the Configuration blase, make sure you pick a Windows instance type in the second step, provide a DNS label and proceed to click OK until the new instance gets created.

New Azure Container Instance - Configuration

Once the instance creation has finished, navigate back to the Azure Container Instance resource section in the Azure Portal, you should see your new instance listed. Click on its name to open its properties panel.

Azure Portal Container

Under the FQDN header, copy the URL of our new container, and navigate to it in a new browser window.

Azure Container Instance Fully Qualified Domain Name

We now have our Application containerized as a Docker container running inside of Azure Container Instances!

My Containerized Application