0
0
Azurecloud~5 mins

Azure Container Instances (ACI) for simple runs - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you want to run a small app or task in the cloud without setting up a full server or complex system. Azure Container Instances lets you quickly run containers in the cloud without managing servers.
When you want to run a one-time script or job in a container without managing servers
When you need to test a containerized app quickly in the cloud
When you want to run a small web app or API without setting up a full Kubernetes cluster
When you want to run background tasks or batch jobs on demand
When you want to avoid the overhead of managing virtual machines for simple container runs
Config File - aci-deployment.yaml
aci-deployment.yaml
apiVersion: 2019-12-01
location: eastus
name: mycontainerinstance
properties:
  containers:
  - name: myapp
    properties:
      image: mcr.microsoft.com/azuredocs/aci-helloworld
      resources:
        requests:
          cpu: 1
          memoryInGb: 1.5
  osType: Linux
  restartPolicy: Never
  ipAddress:
    type: Public
    ports:
    - protocol: tcp
      port: 80
  tags: {}
type: Microsoft.ContainerInstance/containerGroups

This YAML file defines an Azure Container Instance named mycontainerinstance in the eastus region.

It runs a container called myapp using a simple hello world image.

The container requests 1 CPU and 1.5 GB memory.

The OS is Linux and the container will not restart automatically after it stops.

It exposes port 80 publicly so you can access the app from the internet.

Commands
Create a resource group in Azure to hold your container instance. This groups related resources together.
Terminal
az group create --name myResourceGroup --location eastus
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup", "location": "eastus", "managedBy": null, "name": "myResourceGroup", "properties": { "provisioningState": "Succeeded" }, "tags": {}, "type": "Microsoft.Resources/resourceGroups" }
--name - Sets the name of the resource group
--location - Sets the Azure region for the resource group
Create the Azure Container Instance using the YAML file. This deploys the container to the cloud.
Terminal
az container create --resource-group myResourceGroup --file aci-deployment.yaml
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.ContainerInstance/containerGroups/mycontainerinstance", "location": "eastus", "name": "mycontainerinstance", "properties": { "containers": [ { "name": "myapp", "properties": { "image": "mcr.microsoft.com/azuredocs/aci-helloworld", "resources": { "requests": { "cpu": 1, "memoryInGb": 1.5 } }, "instanceView": { "state": "Running" } } } ], "ipAddress": { "ip": "52.170.12.34", "ports": [ { "port": 80, "protocol": "TCP" } ], "type": "Public" }, "osType": "Linux", "provisioningState": "Succeeded", "restartPolicy": "Never" }, "tags": {}, "type": "Microsoft.ContainerInstance/containerGroups" }
--resource-group - Specifies the resource group to deploy to
--file - Specifies the YAML file with container configuration
Get the public IP address of the container instance so you can access the app in a browser.
Terminal
az container show --resource-group myResourceGroup --name mycontainerinstance --query ipAddress.ip --output tsv
Expected OutputExpected
52.170.12.34
--query - Filters output to show only the IP address
--output - Formats output as plain text
View the logs from the container to check its output or debug if needed.
Terminal
az container logs --resource-group myResourceGroup --name mycontainerinstance
Expected OutputExpected
Hello from Azure Container Instances!
Key Concept

If you remember nothing else from this pattern, remember: Azure Container Instances let you run containers quickly in the cloud without managing servers.

Common Mistakes
Not creating a resource group before deploying the container
Azure requires a resource group to organize resources; deployment will fail without it.
Always run 'az group create' first to create a resource group.
Using a container image that does not expose the port defined in the YAML
The container won't be reachable on the expected port, causing connection failures.
Ensure the container image listens on the port you expose in the configuration.
Forgetting to check the container's IP address after deployment
Without the IP, you cannot access the running container's app or service.
Use 'az container show' with query to get the public IP.
Summary
Create a resource group to hold your Azure resources.
Deploy the container instance using a YAML configuration file.
Retrieve the container's public IP to access the app.
Check container logs to verify it is running correctly.