Run Containers by Using Azure Container Instances
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.
Table of Contents
Challenge
Housekeeping
Challenge
Create an Instance of Azure Container Registry (ACR)
From the Bash command prompt in Cloud Shell:
Retrieve the name of the resource group already deployed in the lab environment using the az group list command, and copy the name of the resource group.
Set up three variables as follows:
rg=<SOURCE_GROUP_NAME>
name=acrlabdemo
acr="$name$RANDOM"
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 environment variables for the first two arguments, and set the SKU to Basic. This step may take several minutes to complete.
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.
Challenge
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.
Change to the clouddrive directory with cd clouddrive.
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
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
--imageargument issample/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 isclouddrive. If you leave out the period, you will likely get an error. The build and push will take a few minutes to complete.
Close or minimize the Cloud Shell, and return to the resource group overview page in the portal.
Find and select the new ACR instance and go to Repositories to confirm that the image exists in the repository.
Challenge
Deploy an Image to Azure Container Instances (ACI)
In the Azure portal, create a new ACI. Ensure that you:
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.
Troubleshooting: