Quickstart: Deploy a container instance in Azure using an ARM template

Use Azure Container Instances to run serverless Docker containers in Azure with simplicity and speed. Deploy an application to a container instance on-demand when you don't need a full container orchestration platform like Azure Kubernetes Service. In this quickstart, you use an Azure Resource Manager template (ARM template) to deploy an isolated Docker container and make its web application available with a public IP address.

An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it.

If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. The template will open in the Azure portal.

Deploy to Azure

Prerequisites

If you don't have an Azure subscription, create a free account before you begin.

Review the template

The template used in this quickstart is from Azure Quickstart Templates.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "name": {
      "type": "string",
      "metadata": {
        "description": "Name for the container group"
      },
      "defaultValue": "acilinuxpublicipcontainergroup"
    },
    "image": {
      "type": "string",
      "metadata": {
        "description": "Container image to deploy. Should be of the form repoName/imagename:tag for images stored in public Docker Hub, or a fully qualified URI for other registries. Images from private registries require additional registry credentials."
      },
      "defaultValue": "mcr.microsoft.com/azuredocs/aci-helloworld"
    },
    "port": {
      "type": "string",
      "metadata": {
        "description": "Port to open on the container and the public IP address."
      },
      "defaultValue": "80"
    },
    "cpuCores": {
      "type": "string",
      "metadata": {
        "description": "The number of CPU cores to allocate to the container."
      },
      "defaultValue": "1.0"
    },
    "memoryInGb": {
      "type": "string",
      "metadata": {
        "description": "The amount of memory to allocate to the container in gigabytes."
      },
      "defaultValue": "1.5"
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "restartPolicy": {
      "type": "string",
      "defaultValue": "always",
      "metadata": {
        "description": "The behavior of Azure runtime if container has stopped."
      },
      "allowedValues": [
        "never",
        "always",
        "onfailure"
      ]
    }
  },
  "resources": [
    {
      "name": "[parameters('name')]",
      "type": "Microsoft.ContainerInstance/containerGroups",
      "apiVersion": "2019-12-01",
      "location": "[parameters('location')]",
      "properties": {
        "containers": [
          {
            "name": "[parameters('name')]",
            "properties": {
              "image": "[parameters('image')]",
              "ports": [
                {
                  "port": "[parameters('port')]"
                }
              ],
              "resources": {
                "requests": {
                  "cpu": "[parameters('cpuCores')]",
                  "memoryInGb": "[parameters('memoryInGb')]"
                }
              }
            }
          }
        ],
        "osType": "Linux",
        "restartPolicy": "[parameters('restartPolicy')]",
        "ipAddress": {
          "type": "Public",
          "ports": [
            {
              "protocol": "Tcp",
              "port": "[parameters('port')]"
            }
          ]
        }
      }
    }
  ],
  "outputs": {
    "containerIPv4Address": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.ContainerInstance/containerGroups/', parameters('name'))).ipAddress.ip]"
    }
  }
}

The following resource is defined in the template:

More Azure Container Instances template samples can be found in the quickstart template gallery.

Deploy the template

  1. Select the following image to sign in to Azure and open a template. The template creates a registry and a replica in another location.

    Deploy to Azure

  2. Select or enter the following values.

    • Subscription: select an Azure subscription.
    • Resource group: select Create new, enter a unique name for the resource group, and then select OK.
    • Location: select a location for the resource group. Example: Central US.
    • Name: accept the generated name for the instance, or enter a name.
    • Image: accept the default image name. This sample Linux image packages a small web app written in Node.js that serves a static HTML page.

    Accept default values for the remaining properties.

    Review the terms and conditions. If you agree, select I agree to the terms and conditions stated above.

    Template properties

  3. After the instance has been created successfully, you get a notification:

    Portal notification

The Azure portal is used to deploy the template. In addition to the Azure portal, you can use the Azure PowerShell, Azure CLI, and REST API. To learn other deployment methods, see Deploy templates.

Review deployed resources

Use the Azure portal or a tool such as the Azure CLI to review the properties of the container instance.

  1. In the portal, search for Container Instances, and select the container instance you created.

  2. On the Overview page, note the Status of the instance and its IP address.

    Instance overview

  3. Once its status is Running, navigate to the IP address in your browser.

    App deployed using Azure Container Instances viewed in browser

View container logs

Viewing the logs for a container instance is helpful when troubleshooting issues with your container or the application it runs.

To view the container's logs, under Settings, select Containers > Logs. You should see the HTTP GET request generated when you viewed the application in your browser.

Container logs in the Azure portal

Clean up resources

When you're done with the container, on the Overview page for the container instance, select Delete. When prompted, confirm the deletion.

Next steps

In this quickstart, you created an Azure container instance from a public Microsoft image. If you'd like to build a container image and deploy it from a private Azure container registry, continue to the Azure Container Instances tutorial.

For a step-by-step tutorial that guides you through the process of creating a template, see: