Lesson 2 of 4 Azure Container Services

Running Containers with Azure Container Instances

This lesson explains container groups, the settings used to create a container instance, and the service's storage options and limits.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe container groups.
  • Describe the main settings for creating a container instance, including restart policies.
  • Identify the limitations of Container Instances.

Container groups

The top-level resource in ACI is the container group, a collection of containers scheduled on the same host machine. Containers in a group share a lifecycle, resources, a local network (they reach each other on localhost with different ports) and storage volumes, similar to a Kubernetes pod. A group with one container is the most common case; multi-container groups, used for patterns such as an application with a logging sidecar, are supported on Linux only and are deployed with a YAML file or an ARM template, not the portal's basic form.

The following diagram compares the restart policies of Azure Container Instances for a short nightly script.

Running a 20-minute nightly script at the lowest cost with no servers. Azure Container Instances with restart policy OnFailure retries a crash but stops after success, an Azure Files share holds the results, and automation such as a Logic App starts the container group each night. Billing is per second while it runs.
The scenario is illustrative.
True or false

Container groups

Exam skills 3.3.2

Check how containers in a container group share resources.

Log in to try this activity Interactive activities are free with an account.

Creating a container instance in the portal

The Create container instance wizard sets the resource group, name, region, availability zone (optional), image source (quickstart images, Azure Container Registry, or another registry such as Docker Hub with credentials if private), image, OS type (Linux or Windows) and size (CPU cores and memory in GB). The Networking tab chooses Public (a public IP with an optional DNS name label, giving label.region.azurecontainer.io), Private (deployed into a delegated VNet subnet) or None, and the ports to expose. The Advanced tab sets the restart policy, environment variables (including secure values that are not displayed), a command override and a managed identity.

Restart policyBehaviourUse for
Always (default)Containers are always restartedLong-running services such as web servers
OnFailureRestarted only if the process exits with an errorTasks that must finish successfully
NeverRun once and stopRun-once jobs, builds, scripts
Sort into groups

Which restart policy?

Exam skills 3.3.2

Choose the restart policy for each container.

Log in to try this activity Interactive activities are free with an account.

Storage, logs and limits

Container file systems are temporary, so persistent data uses mounted volumes: an Azure Files share (Linux containers), emptyDir, a Git repo or a secret volume. Container logs and events are viewed on the instance's Containers page or with az container logs and az container attach, and az container exec opens a shell. ACI does not provide autoscaling, load balancing across groups or rolling upgrades; for those, use Azure Container Apps or AKS. ACI is ideal for simple applications, build agents, task automation and bursting from AKS through virtual nodes.

Scenario questions

Living with ACI's limits

Exam skills 3.3.2

Decide how Container Instances handles storage, troubleshooting and scale.

Log in to try this activity Interactive activities are free with an account.
Worked example

A nightly data job

A containerized script processes the previous day's files each night, writing results to a shared location, and takes about 20 minutes. It must not restart after completing successfully, but should retry if it crashes. The team wants the lowest cost and no servers to manage. What should you configure?

Run it in Azure Container Instances with restart policy OnFailure, mount an Azure Files share for the results, and start the container group each night from automation such as a Logic App. Billing is per second only while it runs. Always would restart the script after it finishes, and Never would not retry after a crash.

Check yourself

Which operating system supports multi-container groups in Container Instances?

Show answer

Linux only.

Exam Tips

Remember for the exam

  • A container group's containers share lifecycle, network and volumes; multi-container groups are Linux only.
  • Restart policies: Always (default), OnFailure, Never.
  • Persistent storage: mount an Azure Files share.
  • ACI has no autoscaling; use Container Apps for scaling services.