Azure 容器实例中的容器组Container groups in Azure Container Instances

Azure 容器实例中的顶层资源是容器组。**The top-level resource in Azure Container Instances is the container group. 本文介绍容器组的定义和它们支持的方案类型。This article describes what container groups are and the types of scenarios they enable.

什么是容器组?What is a container group?

容器组是安排在同一主机上的容器集合。A container group is a collection of containers that get scheduled on the same host machine. 容器组中的容器共享生命周期、资源、本地网络和存储卷。The containers in a container group share a lifecycle, resources, local network, and storage volumes. 它与 Kubernetes 中的 Pod 这一概念相似。It's similar in concept to a pod in Kubernetes.

以下关系图显示了一个包含多个容器的容器组示例:The following diagram shows an example of a container group that includes multiple containers:


此示例容器组:This example container group:

  • 安排在一个主机上。Is scheduled on a single host machine.
  • 已分配 DNS 名称标签。Is assigned a DNS name label.
  • 公开一个公共 IP 地址(只有一个公开端口)。Exposes a single public IP address, with one exposed port.
  • 由两个容器组成。Consists of two containers. 其中一个容器侦听端口 80,另一个容器侦听端口 5000。One container listens on port 80, while the other listens on port 5000.
  • 包含两个 Azure 文件共享作为卷装载,每个容器本地装载一个共享。Includes two Azure file shares as volume mounts, and each container mounts one of the shares locally.


多容器组目前仅支持 Linux 容器。Multi-container groups currently support only Linux containers.


下面是部署多容器组的两种常用方法:使用资源管理器模板YAML 文件Here are two common ways to deploy a multi-container group: use a Resource Manager template or a YAML file. 如果需要在部署容器实例时部署其他 Azure 服务资源(例如 Azure 文件共享),建议采用资源管理器模板。A Resource Manager template is recommended when you need to deploy additional Azure service resources (for example, an Azure Files share) when you deploy the container instances. 由于 YAML 格式更简洁,因此,当部署仅包括容器实例时,建议使用 YAML 文件。Due to the YAML format's more concise nature, a YAML file is recommended when your deployment includes only container instances. 有关可设置的属性的详细信息,请参阅资源管理器模板参考YAML 参考文档。For details on properties you can set, see the Resource Manager template reference or YAML reference documentation.

若要保留容器组的配置,可以使用 Azure CLI 命令 az container export 将配置导出到 YAML 文件。To preserve a container group's configuration, you can export the configuration to a YAML file by using the Azure CLI command az container export. 通过导出,可将容器组配置存储在“配置即代码”的版本控制中。Export allows you to store your container group configurations in version control for "configuration as code." 还可以将导出的文件用作使用 YAML 开发新配置时的起点。Or, use the exported file as a starting point when developing a new configuration in YAML.

资源分配Resource allocation

Azure 容器实例通过添加组中实例的资源请求,将 CPU、内存和(可选)GPU(预览版)等资源分配到多容器组。Azure Container Instances allocates resources such as CPUs, memory, and optionally GPUs (preview) to a multi-container group by adding the resource requests of the instances in the group. 以 CPU 资源为例,如果创建包含两个容器实例的容器组,每个实例请求 1 个 CPU,则会为该容器组分配 2 个 CPU。Taking CPU resources as an example, if you create a container group with two container instances, each requesting 1 CPU, then the container group is allocated 2 CPUs.

容器实例的资源用量Resource usage by container instances

为组中的每个容器实例分配该实例的资源请求中指定的资源。Each container instance in a group is allocated the resources specified in its resource request. 但是,如果配置组中容器实例的可选资源限制属性,则该实例使用的最大资源数可能不同。However, the maximum resources used by a container instance in a group could be different if you configure its optional resource limit property. 容器实例的资源限制必须大于或等于必需的资源请求属性。The resource limit of a container instance must be greater than or equal to the mandatory resource request property.

  • 如果未指定资源限制,则容器实例的最大资源用量与其资源请求相同。If you don't specify a resource limit, the container instance's maximum resource usage is the same as its resource request.

  • 如果指定容器实例的限制,则实例的最大用量可能大于请求,但不超过设置的限制。If you specify a limit for a container instance, the instance's maximum usage could be greater than the request, up to the limit you set. 相应地,组中其他容器实例的资源用量可能会降低。Correspondingly, resource usage by other container instances in the group could decrease. 可为容器实例设置的最大资源限制是分配给组的资源总量。The maximum resource limit you can set for a container instance is the total resources allocated to the group.

例如,在包含两个容器实例的组中(每个实例请求 1 个 CPU),一个容器运行的工作负荷可能需要运行比其他实例更多的 CPU。For example, in a group with two container instances each requesting 1 CPU, one of your containers might run a workload that requires more CPUs to run than the other.

在这种情况下,可将容器实例的资源限制设置为最多 2 个 CPU。In this scenario, you could set a resource limit of up to 2 CPUs for the container instance. 此配置允许该容器实例最多使用 2 个 CPU(如果可用)。This configuration allows the container instance to use up to 2 CPUs if available.


服务的底层基础结构使用了容器组的少量资源。A small amount of a container group's resources is used by the service's underlying infrastructure. 你的容器将能够访问分配给该组的大部分而不是全部资源。Your containers will be able to access most but not all of the resources allocated to the group. 因此,为组中的容器请求资源时,请规划一个小型资源缓冲区。For this reason, plan a small resource buffer when requesting resources for containers in the group.

最小和最大分配Minimum and maximum allocation

  • 最少 1 个 CPU 和 1 GB 内存分配到容器组。Allocate a minimum of 1 CPU and 1 GB of memory to a container group. 可为组中的单个容器实例预配少于 1 个 CPU 和 1 GB 内存。Individual container instances within a group can be provisioned with less than 1 CPU and 1 GB of memory.

  • 有关容器组中的最大资源量,请参阅部署区域中 Azure 容器实例的资源可用性For the maximum resources in a container group, see the resource availability for Azure Container Instances in the deployment region.


容器组可以共享面向外部的 IP 地址、该 IP 地址上的一个或多个端口,以及具有完全限定域名 (FQDN) 的 DNS 标签。Container groups can share an external-facing IP address, one or more ports on that IP address, and a DNS label with a fully qualified domain name (FQDN). 若要启用外部客户端来访问组内的容器,必须从该容器公开 IP 地址上的端口。To enable external clients to reach a container within the group, you must expose the port on the IP address and from the container. 删除容器组后,将释放该容器组的 IP 地址和 FQDN。A container group's IP address and FQDN are released when the container group is deleted.

在容器组中,容器实例可以通过任何端口上的本地主机相互访问,即使这些端口未在组的 IP 地址对外公开,或者未从容器公开。Within a container group, container instances can reach each other via localhost on any port, even if those ports aren't exposed externally on the group's IP address or from the container.


可以指定要在容器组内装载的外部卷。You can specify external volumes to mount within a container group. 支持的卷包括:Supported volumes include:

可以将这些卷映射到组中单个容器内的特定路径。You can map those volumes into specific paths within the individual containers in a group.

常见方案Common scenarios

如果希望将单个功能性任务分成少数容器映像,则多容器组十分有用。Multi-container groups are useful in cases where you want to divide a single functional task into a small number of container images. 然后,这些映像可以由不同的团队交付并具有单独的资源需求。These images can then be delivered by different teams and have separate resource requirements.

使用情况示例包括:Example usage could include:

  • 为 Web 应用程序提供服务的容器和从源控件拉取最新内容的容器。A container serving a web application and a container pulling the latest content from source control.
  • 应用程序容器和日志记录容器。An application container and a logging container. 日志记录容器收集主要应用程序输出的日志和指标并将其写入长期存储。The logging container collects the logs and metrics output by the main application and writes them to long-term storage.
  • 应用程序容器和监视容器。An application container and a monitoring container. 监视容器定期向应用程序发送请求,确保该应用程序正常运行和响应,并在应用程序出现异常时发出警报。The monitoring container periodically makes a request to the application to ensure that it's running and responding correctly, and raises an alert if it's not.
  • 前端容器和后端容器。A front-end container and a back-end container. 前端可为 Web 应用程序提供服务,后端运行某个服务来检索数据。The front end might serve a web application, with the back end running a service to retrieve data.

后续步骤Next steps

了解如何通过 Azure 资源管理器模板部署多容器容器组:Learn how to deploy a multi-container container group with an Azure Resource Manager template: