使用ARM模板为容器部署Web App

Cok*_*oke 2 json azure azure-rm-template

我一直在尝试自动将资源部署到Azure上的资源组。现在,我正在使用ARM模板,到目前为止,我已经能够使用模板创建App Insights和App Service Plan。它是这样的:

{
   "apiVersion": "2015-05-01",
   "name": "[variables('servicePlan')]",
   "kind": "linux",
   "type": "Microsoft.Web/serverfarms",
   "location": "[resourceGroup().location]",
   "tags": {
           "displayName": "BTC Push Notification Settings HostingPlan"
    },
    "sku": {
           "name": "[variables('skuNamePlan')]",
           "capacity": "[variables('skuSizePlan')]"
    },
    "properties": {
            "name": "[variables('servicePlan')]"
    }
},
{
    "apiVersion": "2015-05-01",
    "name": "[variables('appInsights')]",
    "type": "Microsoft.Insights/components",
    "location": "southcentralus",
    "tags": {
            "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('appInsights'))]": "Resource",
            "displayName": "BTC Push Notification Settings App Insights"
     },
     "properties": {
            "applicationId": "[variables('appInsights')]"
        }
 }
Run Code Online (Sandbox Code Playgroud)

我很难创建用于容器的Web App,并使用ARM模板将其指向我的docker映像。我已经手动完成它和它的工作,我也做到了,通过azure-cli这样az webapp create --resource-group ExampleGroupAlpina --plan myAppServicePlan --name DockerContainer --deployment-container-image-name this-is-my-image/sample-docker,这工作过。如果有人建议使用ARM模板为容器创建此Web App,将不胜感激。

TPP*_*PPZ 5

以下 ARM 模板对我有用。

  • 它允许指定私有 Azure 容器注册表的身份验证详细信息。
  • 还要确保 docker 映像名称遵循以下模式:_MY_REGISTRY_USERNAME_-on.azurecr.io/_MY_NAMESPACE_/_MY_DOCKER_IMAGE_NAME_:latest

az这样运行命令:

az group deployment create \
  --name "deployAzureApp" \
  --resource-group <MY_RESOURCE_GROUP_NAME> \
  --template-file <MY_ARM_JSON_TEMPLATE>.json  --verbose --debug
Run Code Online (Sandbox Code Playgroud)

以下是 Azure 资源管理器 (ARM) JSON 模板:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "appName": {
      "type": "String",
      "defaultValue": "_MY_APP_NAME_"
    },
    "dockerImageName": {
      "type": "String",
      "defaultValue": "_MY_REGISTRY_USERNAME_-on.azurecr.io/_MY_NAMESPACE_/_MY_DOCKER_IMAGE_NAME_:latest"
    },
    "dockerRegistryUrl": {
      "type": "String",
      "defaultValue": "https://_MY_REGISTRY_USERNAME_-on.azurecr.io"
    },
    "dockerRegistryUsername": {
      "type": "String",
      "defaultValue": "_MY_REGISTRY_USERNAME_"
    },
    "dockerRegistryPassword": {
      "type": "String",
      "defaultValue": "_MY_REGISTRY_PSW_"
    },
    "servicePlanName": {
      "type": "String",
      "defaultValue": "_MY_SERVICE_PLAN_NAME_"
    },
    "appLocation": {
      "type": "String",
      "defaultValue": "_MY_REGION_"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2016-08-01",
      "name": "[parameters('appName')]",
      "kind": "app,linux,container",
      "location": "[parameters('appLocation')]",
      "properties": {
        "name": "[parameters('appName')]",
        "siteConfig": {
          "linuxFxVersion": "[concat('DOCKER|', parameters('dockerImageName'))]",
          "alwaysOn": true,
          "appSettings": [
            {
              "name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
              "value": "false"
            },
            {
              "name": "DOCKER_REGISTRY_SERVER_URL",
              "value": "[parameters('dockerRegistryUrl')]"
            },
            {
              "name": "DOCKER_REGISTRY_SERVER_USERNAME",
              "value": "[parameters('dockerRegistryUsername')]"
            },
            {
              "name": "DOCKER_REGISTRY_SERVER_PASSWORD",
              "value": "[parameters('dockerRegistryPassword')]"
            }
          ]
        },
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('servicePlanName'))]"
      }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

  • 这个答案对我来说不再适用,我得到“参数 LinuxFxVersion 的值无效。” 提交类似以下内容时:“linuxFxVersion”:“username.azurecr.io/namespace/imagename:latest” (2认同)

小智 5

对我来说,其他任何答案都行不通。在Azure支持和其他答案的帮助下,我想到了以下模板,该模板成功地使用运行Linux容器的容器的Linux应用服务创建了应用服务计划,该容器运行来自Azure容器存储库的自定义Docker映像:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "environment":{
      "type": "string"
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location (region) for all resources."
      }
    },   
    "appServiceSku": {
      "type": "string",
      "defaultValue": "B1",
      "metadata": {
        "description": "The SKU of App Service Plan "
      }
    },
    "dockerImageName": {
      "type": "string",
      "defaultValue": "_MY_REGISTRY_USERNAME_.azurecr.io/_MY_NAMESPACE_/_MY_DOCKER_IMAGE_NAME_:_TAG_"
    },
    "dockerRegistryUrl": {
      "type": "string",
      "defaultValue": "https://_MY_REGISTRY_USERNAME_.azurecr.io"
    },
    "dockerRegistryUsername": {
      "type": "string",
      "defaultValue": "_MY_REGISTRY_USERNAME_"
    },
    "dockerRegistryPassword": {
      "type": "string",
      "defaultValue": "_MY_REGISTRY_PSW_"
    },
    "_artifactsLocation": {
      "type": "string"
    },
    "_artifactsLocationSasToken": {
      "type": "securestring"
    }
  },
  "variables": {
    "name": "projectname-",
    "webAppPortalName": "[concat(variables('name'), parameters('environment'), '-webapp')]",
    "appServicePlanName": "[concat(variables('name'), parameters('environment'),'-hosting')]",
  "resources": [       
    {
      "apiVersion": "2017-08-01",
      "type": "Microsoft.Web/serverfarms",
      "kind": "linux",
      "name": "[variables('appServicePlanName')]",
      "location": "[parameters('location')]",
      "comments": "This app service plan is used for the web app and slots.",
      "properties": {
        "reserved": true
      },
      "dependsOn": [],
      "sku": {
        "name": "[parameters('appServiceSku')]"
      }
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2016-08-01",
      "name": "[variables('webAppPortalName')]",
      "kind": "app,linux,container",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
      ],
      "properties": {
        "name": "[variables('webAppPortalName')]",
        "siteConfig": {
          "linuxFxVersion": "[concat('DOCKER|', parameters('dockerImageName'))]",
          "alwaysOn": true,
          "appSettings": [
            {
              "name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
              "value": "false"
            },
            {
              "name": "DOCKER_REGISTRY_SERVER_URL",
              "value": "[parameters('dockerRegistryUrl')]"
            },
            {
              "name": "DOCKER_REGISTRY_SERVER_USERNAME",
              "value": "[parameters('dockerRegistryUsername')]"
            },
            {
              "name": "DOCKER_REGISTRY_SERVER_PASSWORD",
              "value": "[parameters('dockerRegistryPassword')]"
            }
          ]
        },
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
      }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

_artifactsLocation并且_artifactsLocationSasToken不需要值,但是需要以某种方式将它们包括在内。与其他答案的主要区别是在App Service Plan中包含了reserved属性properties

希望这可以减轻我的头痛!