|
| 1 | +--- |
| 2 | +title: Quickstart - create a container instance - Bicep |
| 3 | +description: In this quickstart, you use a Bicep file to quickly deploy a containerized web app that runs in an isolated Azure container instance. |
| 4 | +author: schaffererin |
| 5 | +services: azure-resource-manager |
| 6 | +ms.author: v-eschaffer |
| 7 | +ms.date: 03/10/2022 |
| 8 | +ms.topic: quickstart |
| 9 | +ms.service: container-instances |
| 10 | +ms.custom: subject-armqs, devx-track-js, mode-arm |
| 11 | +--- |
| 12 | + |
| 13 | +# Quickstart: Deploy a container instance in Azure using Bicep |
| 14 | + |
| 15 | +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 a Bicep file to deploy an isolated Docker container and make its web application available with a public IP address. |
| 16 | + |
| 17 | +[!INCLUDE [About Bicep](../../includes/resource-manager-quickstart-bicep-introduction.md)] |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | + |
| 21 | +If you don't have an Azure subscription, create a [free](https://azure.microsoft.com/free/) account before you begin. |
| 22 | + |
| 23 | +## Review the Bicep file |
| 24 | + |
| 25 | +The Bicep file used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/aci-linuxcontainer-public-ip/). |
| 26 | + |
| 27 | +:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.containerinstance/aci-linuxcontainer-public-ip/main.bicep"::: |
| 28 | + |
| 29 | +The following resource is defined in the Bicep file: |
| 30 | + |
| 31 | +* **[Microsoft.ContainerInstance/containerGroups](/azure/templates/microsoft.containerinstance/containergroups)**: create an Azure container group. This Bicep file defines a group consisting of a single container instance. |
| 32 | + |
| 33 | +More Azure Container Instances template samples can be found in the [quickstart template gallery](https://azure.microsoft.com/resources/templates/?resourceType=Microsoft.Containerinstance&pageNumber=1&sort=Popular). |
| 34 | + |
| 35 | +## Deploy the Bicep file |
| 36 | + |
| 37 | +1. Save the Bicep file as **main.bicep** to your local computer. |
| 38 | +1. Deploy the Bicep file using either Azure CLI or Azure PowerShell. |
| 39 | + |
| 40 | + # [CLI](#tab/CLI) |
| 41 | + |
| 42 | + ```azurecli |
| 43 | + az group create --name exampleRG --location eastus |
| 44 | + az deployment group create --resource-group exampleRG --template-file main.bicep |
| 45 | + ``` |
| 46 | +
|
| 47 | + # [PowerShell](#tab/PowerShell) |
| 48 | +
|
| 49 | + ```azurepowershell |
| 50 | + New-AzResourceGroup -Name exampleRG -Location eastus |
| 51 | + New-AzResourceGroupDeployment -ResourceGroupName exampleRG -TemplateFile ./main.bicep |
| 52 | + ``` |
| 53 | +
|
| 54 | + --- |
| 55 | +
|
| 56 | + When the deployment finishes, you should see a message indicating the deployment succeeded. |
| 57 | +
|
| 58 | +## Review deployed resources |
| 59 | +
|
| 60 | +Use the Azure portal, Azure CLI, or Azure PowerShell to list the deployed resources in the resource group. |
| 61 | +
|
| 62 | +# [CLI](#tab/CLI) |
| 63 | +
|
| 64 | +```azurecli-interactive |
| 65 | +az resource list --resource-group exampleRG |
| 66 | +``` |
| 67 | + |
| 68 | +# [PowerShell](#tab/PowerShell) |
| 69 | + |
| 70 | +```azurepowershell-interactive |
| 71 | +Get-AzResource -ResourceGroupName exampleRG |
| 72 | +``` |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +### View container logs |
| 77 | + |
| 78 | +Viewing the logs for a container instance is helpful when troubleshooting issues with your container or the application it runs. Use the Azure portal, Azure CLI, or Azure PowerShell to view the container's logs. |
| 79 | + |
| 80 | +# [CLI](#tab/CLI) |
| 81 | + |
| 82 | +```azurecli-interactive |
| 83 | +az container logs --resource-group exampleRG --name acilinuxpublicipcontainergroup |
| 84 | +``` |
| 85 | + |
| 86 | +# [PowerShell](#tab/PowerShell) |
| 87 | + |
| 88 | +```azurepowershell-interactive |
| 89 | +Get-AzContainerInstanceLog -ResourceGroupName exampleRG -ContainerGroupName acilinuxpublicipcontainergroup -ContainerName acilinuxpublicipcontainergroup |
| 90 | +``` |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +> [!NOTE] |
| 95 | +> It may take a few minutes for the HTTP GET request to generate. |
| 96 | +
|
| 97 | +## Clean up resources |
| 98 | + |
| 99 | +When no longer needed, use the Azure portal, Azure CLI, or Azure PowerShell to delete the container and all of the resources in the resource group. |
| 100 | + |
| 101 | +# [CLI](#tab/CLI) |
| 102 | + |
| 103 | +```azurecli-interactive |
| 104 | +az group delete --name exampleRG |
| 105 | +``` |
| 106 | + |
| 107 | +# [PowerShell](#tab/PowerShell) |
| 108 | + |
| 109 | +```azurepowershell-interactive |
| 110 | +Remove-AzResourceGroup -Name exampleRG |
| 111 | +``` |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## Next steps |
| 116 | + |
| 117 | +In this quickstart, you created an Azure container instance using Bicep. 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. |
| 118 | + |
| 119 | +> [!div class="nextstepaction"] |
| 120 | +> [Tutorial: Create a container image for deployment to Azure Container Instances](./container-instances-tutorial-prepare-app.md) |
0 commit comments