For this ATA Project, you're going to get a glimpse at the Azure Container Instance service by Microsoft. Azure Container Instance is a hosted Kubernetes cluster allowing you to deploy any Docker image (Windows and Linux) and run it as a container. Each Azure Docker container runs as a stand-alone container, using its own allocated CPU and memory.

In this project, you'll learn how to deploy and run your first Azure Container Instance, based on a sample ASP.NET container image from Microsoft in the Azure public cloud.

By the end of this project, you'll have an ASP.NET website running in a Docker container hosted by the Azure Container Instance service.

Environment and Knowledge Requirements

To get the most out of this project walkthrough, you should have the following:

  1. A local Windows 10 client with Docker Desktop installed.
  2. A Microsoft Azure account
  3. Access to an Azure account with permissions to deploy a container to Azure Container Registry
  4. The Windows Azure CLI installed. You'll be learning from the command line.
  5. A beginner understanding of containers and Docker.
  6. A registered Docker ID.
Note that if you don’t like the example chosen in this project, you can always use another container image on the Docker Hub.

Without further ado, let's get into building this Project!

Running a Docker Container

To avoid any frustration later on when something is not working, always first validate the Docker Engine is running. To do so, open a command prompt or PowerShell session and run docker info.

You can see below the type of output you should receive.

Inspecting information about the local Docker installation

To validate you can bring up a Docker container, run docker run hello-world. Behind the scenes the docker command performs a few steps:

  1. Looks for a container called hello-word locally on your Windows 10 computer.
  2. When not found, it then reaches out to the public Docker Hub repository to look for the latest version of a container with the name hello-world.
  3. When the container is found, it's then downloaded from the Docker Hub repository.
  4. Once downloaded, the container is brought up and executes startup instructions provided within the image the container is using.

You can see some example output below.

Download a sample Docker container called hello-world

Starting a Sample ASP.NET Container

Now that you know how to download a Docker container and run it, now download an run the container you'll be working with in this Project. This Docker container is an ASP.Net Core web app image.

To download the Project image, run the following command:

docker run --name aspnetcore_sample --rm -it -p 8000:80

This command does the following:

  1. Since the Docker image isn't available locally, Docker downloads a container called aspnetapp from another public container registry hosted by Microsoft located at in the dotnet/core/samples directory. The container registry is similar to the public Docker Hub, but is maintained by Microsoft and only hosts Microsoft container images.
  2. Runs the container on your local computer.
  3. (-p 8000:80) - Maps the listening TCP port 80 on the container to TCP port 8000. This allows you to access the web app at port 8000 locally.
  4. (-it) - The container will be launch interactively meaning you will be immediately brought into the console when it starts.
  5. (—rm) - When the container is stopped, it will be removed.

You can see below that output you can expect.

Downloading a container instance from Microsoft

6.   From your browser, connect to this running container application by browsing to http://localhost:8000. You should see the ASP.Net sample web app

Creating an Azure Container Registry (ACR) Instance

Once you have the ASP.NET container downloaded to your local computer, it's now time to migrate and run this container in Azure. To do this, we'll push the demo container to Azure Container Registry (ACR). ACR is a service that allows you to deploy and run Docker containers directly within Azure.

  1. Log into the Azure Portal.
  2. Click on the terminal icon at the top to start Azure Cloud Shell.

3.   Make sure you choose the Bash shell as shown below.

4.   Create an Azure resource group to put the an instance of ACR in using the az group create command below.

 az group create --name <RGname> --location <Azure Region of choice>

5.   Now create the ACR inside of the resource group using the az acr create command. Below you can see an example of creating an ACR with a Basic SKU using the admin-enabled parameter set to true. This is set to true because it allows you to perform resource management later on.

 az acr create --resource-group <RGname> --name <ACRname> --sku Basic
 --admin-enabled true

Once you're done, you should now have an ACR instance running inside of your resource group.

Connecting to the ACR Instance Locally

Now you need to move from the Azure Cloud Shell to your local Windows computer to finish with the set up.

  1. On your local machine, launch PowerShell or a command prompt with administrative rights. I'll be using PowerShell.
  2. Authenticate to Azure with the Azure CLI by running az login and follow the instructions to provide your credentials.
  3. Once authenticated successfully, you should see some JSON output indicating the user you just authenticated with.

4.   Next, authenticate to the ACR instance you just created in the Azure Cloud Shell using the as acr login command using the below command. Below you can see I'm connecting to an ACR instance called nopacr1, in Azure resource group NOPRG.

az acr login --name <ACR-Name> --resource-group <RG Name>

Updating The Docker Image Tag

You're now ready to push your local Docker image to your ACR instance. But you must first fulfill an ACR dependency. All Docker images pushed to ACR instance must have the name of the ACR instance in the image name.

  1. Find the Docker image ID number or image name using the command docker images.

2.   Update the Docker image tag for the Docker image by running the docker tag command as shown below. If you're following the naming convention, use the ACR name of NOPACR1 and define the tag as For the image itself, use the name dotnetsample.

 docker tag <ACRName><imagenameofchoice>

3.   Verify the tag has been applied using the docker images command again. You should now see the tag has been updated.

Uploading the Docker Image to the ACR Instance and Verify

  1. Now upload the local image to the ACR instance using the docker push command as shown below providing the dns name label where the ACR instance is located.
 docker push <ACRName><nameofimage>

2.   Once uploaded, verify the push to the ACR instance went fine by using the Azure Portal by navigating to All Services —> Azure Container Registries and selecting the ACR instance you created earlier.

3.   In the blade menu to the left under the Services section, click Repositories. The Docker image just pushed the your ACR instance, should show up here.

4.   Click on the image and you will see it's version and some other useful information.

Running the ACR Instance (ACI)

You've now created an ACR instance, tagged a Docker container image with the ACR name as a reference, and pushed the image to the ACR instance. Now it's time to use Azure Container Instance (ACI) to run the Docker image stored in your ACR instance.

  1. Continuing from the previous step, click the ... next to latest, and choose Run instance. This will open the Create Container Instance blade.

2.   Complete the fields in the Create container instance box below using the following information:

  • Container Name - any name you'd like to use for this running container
  • OS type - Linux (This depends on the source container. If you're using the same container in this Project, this may be Windows.)
  • Subscription - your Azure Subscription
  • Resource Group - any existing or new Azure Resource Group to add the container instance into
  • Location - based on the resource group

For your Project ASP.NET container, you can leave all other settings unchanged. In a production environment, depending what the container is running, you might need to change these settings.

3.   Press OK to create the Container instance.
4.   Once the container instance has been deployed, you should see a page that looks like the example below.

5.   Once the deployment is finished, open the ACI in the portal by navigating to All Services —> Container Instances. Once here, browse to the ACI that just got created. You should see the instance shown as below.

6.   Copy the IP address in the upper-right corner and paste it into a web browser. Your  sample ASP.NET web app should load from your ACI and display a web page as shown below.

If you're done with this container, you can then use the az container delete command to remove the container.