当其中一个容器终止时停止容器实例组

Stop container instances group when one of the containers is terminated

我正在创建一个容器组,其中包含一个在网站上运行 E2E 的容器。当其中一个容器停止 运行 时,如何停止整个组? (在本例中为 E2E 测试)

我正在通过管道创建它,我需要在测试完成后停止前端容器。

apiVersion: 2018-10-01
location: northeurope
name: e2e-uat
properties:
  containers:
    # name of the instance in Azure.
    - name: e2etestcafe
      properties:
        image: registry.azurecr.io/e2e/e2etestcafe:latest
        resources:
          requests:
            cpu: 1
            memoryInGb: 3
    - name: customerportal
      properties:
        image: registry.azurecr.io/e2e/customerportal:latest
        resources:
          requests:
            cpu: 1
            memoryInGb: 1
        ports:
          - port: 80
  osType: Linux
  restartPolicy: never
tags: null
type: Microsoft.ContainerInstance/containerGroups

对于这个要求,据我所知,ACI 没有您期望的功能。所以你需要自己检查容器的状态。

我建议您创建一个带有循环的脚本来检查容器的状态,直到它满足您预期的情况,然后停止整个容器组。在 Azure DevOps 中,您可以使用具有三个阶段的发布管道,一个用于创建,第二个用于使用 运行 脚本检查状态,第三个用于停止容器组。

要检查容器的状态,我认为下面的 CLI 命令很有用:

az container show -g myResourceGroup -n myContainerGroup --query containers[*].instanceView.currentState.state

它将所有容器的状态输出到一个数组中。