Overview

This guide will walk you through deploying a containerized application to Azure Container Instances (ACI) using the Azure CLI. ACI allows you to run containers in Azure without managing virtual machines or orchestrators.

Prerequisites

Steps

Sign in to Azure

Open your terminal or command prompt and sign in to your Azure account:

az login

Follow the instructions to authenticate.

Create a resource group

A resource group is a logical container for your Azure resources. Create one for this quickstart:

az group create --name myResourceGroup --location eastus
Note: Replace myResourceGroup with a unique name and eastus with your preferred Azure region.

Deploy a container

Use the az container create command to deploy a simple container. This example deploys a container running the Azure CLI sample image:

az container create --resource-group myResourceGroup --name myaci-container --image mcr.microsoft.com/azuredocs/aci-helloworld --dns-name-label myaci-helloworld --ports 80

This command does the following:

  • --resource-group: Specifies the resource group created in the previous step.
  • --name: Assigns a name to your container instance.
  • --image: Specifies the Docker image to use.
  • --dns-name-label: Creates a public DNS name for the container.
  • --ports: Exposes port 80 on the container.

Upon successful deployment, you will see output similar to this:

{ "id": "/subscriptions/...", "identity": null, "location": "eastus", "name": "myaci-container", "properties": { "containers": [ { "name": "aci-helloworld", "properties": { "instanceView": { "containerState": { "state": "running", "startTime": "2023-10-27T10:00:00Z" } }, "resources": { "requests": { "cpu": 1.0, "memoryInGB": 1.5 } }, "image": "mcr.microsoft.com/azuredocs/aci-helloworld" } } ], "ipAddress": { "fqdn": "myaci-helloworld.eastus.azurecontainer.io", "ip": "...", "ports": [ { "port": 80, "protocol": "TCP" } ], "type": "Public" }, "osType": "Linux", "provisioningState": "Succeeded" }, "resourceGroup": "myResourceGroup", "tags": {}, "type": "Microsoft.ContainerInstance/containerGroups" }

Verify the deployment

You can verify the deployment by browsing to the FQDN (Fully Qualified Domain Name) of your container. Find the FQDN in the output from the previous step or by running:

az container show --resource-group myResourceGroup --name myaci-container --query "{FQDN:ipAddress.fqdn}" --output tsv

Open this FQDN in your web browser. You should see a message like "Hello World!" indicating your container is running.

Note: DNS propagation might take a few minutes.

Clean up resources

To avoid incurring further charges, delete the resource group and all its resources when you are finished:

az group delete --name myResourceGroup --yes --no-wait

This command deletes the resource group and all resources within it. The --yes flag confirms the deletion, and --no-wait allows the command to return immediately while the deletion happens in the background.

Next Steps

Congratulations! You have successfully deployed a container to Azure Container Instances. To learn more, explore the following resources: