run-container-images-container-instances
Azure Container Instance (ACI) offers the fastest and simplest way to run a container in Azure, without having to manage any virtual machines and without having to adopt a higher-level service.
Contents Covered
Benefits of azure container instances and how resources are grouped
deploy a container instance in azure by using the azure cli
start and stop container using policies
set environment variables in your container instance
mount file shares in your container instances
Azure Container Instances
Container Groups
The top-level resource in azure container instances is the container group. Container Group is a collection of containers that get schedules on the same host machine. The containers in a container group share a lifecycle, resources, local network, and storage volumes. This is similar to pod concept in kubernetes.
Multi-container groups currently (as of Nov '23) support only linux containres. For windows containers, azure container instances only supports deployment of a single instance.
Deployment
There are two common ways to deploy a multi-container group
Resource Manager Template
this is recommended when you need to deploy additional Azure service resources when you deploy the container instances.
YAML file
recommended when your deployment includes only container instances.
Resource allocation
ACI allocates resources such as CPU, memory to container group by adding the resource requests of the instance in the group.
Networking
Container groups share an IP address and a port namespace on that IP address. TO enable external clients to reach a container within the group, you must expose the port on the IP address and from the container. Because containers within the group share a port namespace, port mapping isnt supported. Containers within a group can reach each other via loaclhost on the ports that they have exposed, even if those ports arent exposed externally on the groups IP address.
Storage
You can specify external volumes t omount within a container group. You can map those volumes into specific paths within the individual containers in a group. Azure File share, Secret, Empty directory, Clone git repo are supported volumes.
Creating container instance using Azure CLI
Restart Policies
With a configurable restart policy, you can specify that your containers are stopped when their processes have completed. because container instances are billed by second, you are charged only for the compute resources used while the container executing your task is running.
When you create a container group in azure container instances, you can specify one of three restart policy settings.
Always
- containers in the container group are always restarted. This is the default setting applied when no restart policy is specifiedNever
- containers in the container group are never restarted. The containers run at most onceOnFailure
- Containers in the container group are restarted only when the process executed in the container fails(when it terminates with a non-zero exit code). The containers are run at least once.
set env values
These env variables are similar to the --env
command line argument to docker run
command
Envrionment variables with secure values arent visible in your containers properties. Their values can be accessed only from within the container. For example, container properties viewed in the Azure portal or Azure CLI display only a secure variables name not its value
By default Azure container instances are stateless. If container stops or crashes, all of its state is lost. To persist state beyond the lifetime of the container, you must mount a volume from an external store.
ACI can mount an azure file share created with azure files. Azure files offers fully managed file shares in the cloud that are accessible via the industry standard SMB protocol. Using an azure file share with azure container instances provides file-sharing features similar to using an azure file share with azure virtual machines.
Limitations of file sharing
You can only mount azure files shares to linux containers
azure file share volume mount requires the linux container run as root
azure file share volume mounts are limited to CIFS support
Last updated