容器实例仅在从ARM模板进行的首次部署中运行

时间:2019-02-19 10:51:29

标签: azure azure-container-instances

我正在尝试通过ARM模板创建具有文件共享的存储帐户。为此,我要创建存储帐户,然后在容器实例as described here中运行az CLI命令。

模板可以很好地部署,但是麻烦的是该容器仅在第一次运行时启动。后续部署不会导致容器实例启动,因此,如果文件共享已被删除(人为错误),则不会重新创建。

我无法使用完整的部署,因为资源组中还有其他资源。

我已经咨询过documentation,但是那里似乎没有任何东西。

有没有告诉容器实例总是启动?

这是我正在使用的示例模板-

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageAccountType": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_ZRS"
      ],
      "metadata": {
        "description": "Storage Account type"
      }
    },
    "storageAccountName": {
      "type": "string",
      "defaultValue": "[uniquestring(resourceGroup().id)]",
      "metadata": {
        "description": "Storage Account Name"
      }
    },
    "fileShareName": {
      "type": "string",
      "metadata": {
        "description": "File Share Name"
      }
    },
    "containerInstanceLocation": {
      "type": "string",
      "defaultValue": "[parameters('location')]",
      "allowedValues": [
        "westus",
        "eastus",
        "westeurope",
        "southeastaisa",
        "westus2"
      ],
      "metadata": {
        "description": "Container Instance Location"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    }
  },
  "variables": {
    "image": "microsoft/azure-cli",
    "cpuCores": "1.0",
    "memoryInGb": "1.5",
    "containerGroupName": "createshare-containerinstance",
    "containerName": "createshare"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[parameters('storageAccountName')]",
      "apiVersion": "2017-10-01",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('storageAccountType')]"
      },
      "kind": "Storage",
      "properties": {}
    },
    {
      "name": "[variables('containerGroupName')]",
      "type": "Microsoft.ContainerInstance/containerGroups",
      "apiVersion": "2018-02-01-preview",
      "location": "[parameters('containerInstanceLocation')]",
      "dependsOn": [
        "[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
      ],
      "properties": {
        "containers": [
          {
            "name": "[variables('containerName')]",
            "properties": {
              "image": "[variables('image')]",
              "command": [
                "az",
                "storage",
                "share",
                "create",
                "--name",
                "[parameters('fileShareName')]"
              ],
              "environmentVariables": [
                {
                  "name": "AZURE_STORAGE_KEY",
                  "value": "[listKeys(parameters('storageAccountName'),'2017-10-01').keys[0].value]"
                },
                {
                  "name": "AZURE_STORAGE_ACCOUNT",
                  "value": "[parameters('storageAccountName')]"
                }
              ],
              "resources": {
                "requests": {
                  "cpu": "[variables('cpuCores')]",
                  "memoryInGb": "[variables('memoryInGb')]"
                }
              }
            }
          }
        ],
        "restartPolicy": "OnFailure",
        "osType": "Linux"
      }
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

如果在使用az容器删除之间从Azure门户或az cli槽中手动删除ACI,该怎么办。据我了解,Azure容器实例是可抛弃的。当我要部署新容器时,通常只删除旧容器。当然,这通常是通过CI&CD渠道(例如Jenkins)完成的。

编辑: ARM模板仅在找不到资源时启动容器,但是因为它确实找到了ACI,所以它什么也不做。恕我直言,您不应将ARM模板用于容器管理。