Run Containers by Using Azure Container Instances

1.25 hours
  • 4 Learning Objectives

About this Hands-on Lab

In this lab, you will get some practice with both Azure Container Instances and Azure Container Registry. First, you’ll jump into Azure Cloud Shell to create an Azure Container Registry. Then, you will add a simple Docker container image to the registry. Once the container image is pushed to the registry, you will move to the Azure portal to run an instance of the container in Azure Container Instances. To be successful completing the lab on your own, you should be familiar with the Azure portal and Azure CLI, but anyone with an interest in learning more about these two services for containerized code can use the lab guide and solution videos to work through the objectives successfully.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Housekeeping
  1. Open an incognito or in-private window, and log in to the Azure portal using the username and password provided in the lab environment.
  2. From within the portal, initiate the Cloud Shell, and when prompted, select a Bash shell (versus PowerShell). When prompted again, set up the backing storage. Be sure that you select Show advanced settings and not Create storage. The latter will cause an error. Set up a new storage account with a universally unique name.
  3. Wait for the command prompt to appear.
Create an Instance of Azure Container Registry (ACR)

From the Bash command prompt in Cloud Shell:

  1. Retrieve the name of the resource group already deployed in the lab envrionment using the az group list command, and copy the name of the resource group.
  2. Set up three variables as follows:

    rg=<SOURCE_GROUP_NAME>
    name=acrlabdemo
    acr="$name$RANDOM"
  3. Set up a new ACR using the az acr create command. You will need to pass arguments for the resource group, the name of the new ACR, and the service tier, or SKU. Hint: Use the rg and acr envrionment variables for the first two arguments, and set the SKU to Basic. This step may take several minutes to complete.
  4. Enable an admin user for the registry using the az acr update command. You will need to pass arguments for the ACR name (using the acr environment variable) and then set the admin-enabled argument to true.
Build and Push a Container Image to ACR

You should still be in the Cloud Shell session you had opened when creating the ACR instance.

  1. Change to the clouddrive directory with cd clouddrive.

  2. Create a simple, one-line Dockerfile, called "Dockerfile" with the command, below, which will create the file in your clouddrive directory.

    echo FROM mcr.microsoft.com/hello-world > Dockerfile
  3. Build (and push) a new imagine in your ACR, using the Dockerfile you just created using the az acr build command. You will need to pass three arguments: the image, the registry name, and the Dockerfile name.

    Hints: The value for the --image argument is sample/hello-world:v1. After the argument for the Dockerfile name, add a space and then a period ("."); the period indicates that the file can be found at the root of the current directory, which is clouddrive. If you leave out the period, you will likely get an error. The build and push will take a few minutes to complete.

  4. Close or minimize the Cloud Shell, and return to the resource group overview page in the portal.

  5. Find and select the new ACR instance and go to Repositories to confirm that the image exists in the repository.

Deploy an Image to Azure Container Instances (ACI)

In the Azure portal, create a new ACI. Ensure that you:

  1. Assign it to the existing resource group; do not create a new one.
  2. Leave the region defaulted, and name your container anything you wish.
  3. Use the image stored in your ACR.

    Hint: Once you select Azure Container Registry for the Image Source, it should default to your ACR and the sample image. If not, see the troubleshooting tips, below.

  4. Review and create the ACI. It will take a few minutes to deploy.
  5. Go to the resource and select Start. You can monitor the start-up progress in Notifications.
  6. When the container has started, navigate to Containers and Logs to see a message confirming that your installation is working.

Troubleshooting:

  • When working through the ACI wizard, if the ACR and image do not appear automatically when you choose Azure Container Registry for the Image Source, you may need to refresh the admin access (which you did at the command line earlier in the lab). To do that in the portal, return to the ACR Overview page, and select Update near the top of the page. Toggle the Admin user to Disabled and Save. Then, toggle the Admin user back to Enabled and Save again. Return to the ACI wizard, and you should see the ACR and the sample image available in the registry and image fields.
  • When you start your container in ACI, you may get an error message that says the container is "still transitioning." Wait a couple of minutes and try again.

Additional Resources

Suppose you are part of a team building a proof-of-concept for your organization. Your team wants to test the process of deploying a Docker container image stored in a repository on Azure Container Registry, or ACR, and then deploying and running the image in Azure Container Instances, or ACI. This lab allows you to practice working with these resources at both the command line and in the Azure portal UI.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?