- Lab
- A Cloud Guru
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.
Path Info
Table of Contents
-
Challenge
Housekeeping
- Open an incognito or in-private window, and log in to the Azure portal using the username and password provided in the lab environment.
- From within the portal, initiate the Cloud Shell, and when prompted, select a Bash shell (versus PowerShell).
- When prompted, choose "Mount a Storage Account."
- Choose the lab subscription and click Apply.
- Select the storage account that's already been deployed for you.
- Select the one, existing, resource group.
- Create a new fileshare and name it "fileshare" (all lower-case)
- Click Apply.
- Wait for the command prompt to appear.
-
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 therg
andacr
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 theacr
environment variable) and then set theadmin-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 withcd 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
--image
argument 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:
- Assign it to the existing resource group; do not create a new one.
- Leave the region defaulted, and name your container anything you wish.
- 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.
- Skip all other tabs in the wizard, and proceed to review and create the ACI. It will take a few minutes to deploy.
- Go to the resource and select Start. You can monitor the start-up progress in Notifications.
- When the container has started, navigate to Containers and click Logs to confirm 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.
What's a lab?
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.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.