Tutorial: Deploy a container application to Azure Container Instances
This is the final tutorial in a three-part series. Earlier in the series, a container image was created and pushed to Azure Container Registry. This article completes the series by deploying the container to Azure Container Instances.
In this tutorial, you:
- Deploy the container from Azure Container Registry to Azure Container Instances
- View the running application in the browser
- Display the container's logs
Before you begin
You must satisfy the following requirements to complete this tutorial:
Azure CLI: You must have Azure CLI version 2.0.29 or later installed on your local computer. Run
az --version to find the version. If you need to install or upgrade, see Install the Azure CLI.
Docker: This tutorial assumes a basic understanding of core Docker concepts like containers, container images, and basic
docker commands. For a primer on Docker and container basics, see the Docker overview.
Because the Azure Cloud shell does not include the Docker daemon, you must install both the Azure CLI and Docker Engine on your local computer to complete this tutorial. You cannot use the Azure Cloud Shell for this tutorial.
Deploy the container using the Azure CLI
In this section, you use the Azure CLI to deploy the image built in the first tutorial and pushed to Azure Container Registry in the second tutorial. Be sure you've completed those tutorials before proceeding.
Get registry credentials
When you deploy an image that's hosted in a private container registry like the one created in the second tutorial, you must supply credentials to access the registry. As shown in Authenticate with Azure Container Registry from Azure Container Instances, a best practice for many scenarios is to create and configure an Azure Active Directory service principal with pull permissions to your registry. See that article for sample scripts to create a service principal with the necessary permissions. Take note of the service principal ID and service principal password. You use these credentials when you deploy the container.
You also need the full name of the container registry login server (replace
<acrName> with the name of your registry):
az acr show --name <acrName> --query loginServer
Now, use the az container create command to deploy the container. Replace
<acrLoginServer> with the value you obtained from the previous command. Replace
<service-principal-password> with the service principal ID and password that you created to access the registry. Replace
<aciDnsLabel> with a desired DNS name.
az container create --resource-group myResourceGroup --name aci-tutorial-app --image <acrLoginServer>/aci-tutorial-app:v1 --cpu 1 --memory 1 --registry-login-server <acrLoginServer> --registry-username <service-principal-ID> --registry-password <service-principal-password> --dns-name-label <aciDnsLabel> --ports 80
Within a few seconds, you should receive an initial response from Azure. The
--dns-name-label value must be unique within the Azure region you create the container instance. Modify the value in the preceding command if you receive a DNS name label error message when you execute the command.
Verify deployment progress
To view the state of the deployment, use az container show:
az container show --resource-group myResourceGroup --name aci-tutorial-app --query instanceView.state
Repeat the az container show command until the state changes from Pending to Running, which should take under a minute. When the container is Running, proceed to the next step.
View the application and container logs
Once the deployment succeeds, display the container's fully qualified domain name (FQDN) with the az container show command:
az container show --resource-group myResourceGroup --name aci-tutorial-app --query ipAddress.fqdn
$ az container show --resource-group myResourceGroup --name aci-tutorial-app --query ipAddress.fqdn "aci-demo.eastus.azurecontainer.io"
To see the running application, navigate to the displayed DNS name in your favorite browser:
You can also view the log output of the container:
az container logs --resource-group myResourceGroup --name aci-tutorial-app
$ az container logs --resource-group myResourceGroup --name aci-tutorial-app listening on port 80 ::ffff:10.240.0.4 - - [21/Jul/2017:06:00:02 +0000] "GET / HTTP/1.1" 200 1663 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36" ::ffff:10.240.0.4 - - [21/Jul/2017:06:00:02 +0000] "GET /favicon.ico HTTP/1.1" 404 150 "http://aci-demo.eastus.azurecontainer.io/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"
Clean up resources
If you no longer need any of the resources you created in this tutorial series, you can execute the az group delete command to remove the resource group and all resources it contains. This command deletes the container registry you created, as well as the running container, and all related resources.
az group delete --name myResourceGroup
In this tutorial, you completed the process of deploying your container to Azure Container Instances. The following steps were completed:
- Deployed the container from Azure Container Registry using the Azure CLI
- Viewed the application in the browser
- Viewed the container logs
Now that you have the basics down, move on to learning more about Azure Container Instances, such as how container groups work:
Send feedback about: