クイックスタート: ARM テンプレートを使用して App Service アプリを作成する

Azure Resource Manager テンプレート (ARM テンプレート) と Azure CLI を Cloud Shell で使用して、アプリをクラウドにデプロイすることによって、Azure App Service の使用を開始します。 Resource Manager テンプレートは JavaScript Object Notation (JSON) ファイルであり、プロジェクトのインフラストラクチャと構成が定義されています。 App Service の Free レベルを使用するため、このクイックスタートを完了するのにコストはかかりません。

このクイックスタートを完了するには、アクティブなサブスクリプションが含まれる Azure アカウントが必要です。 Azure アカウントがない場合は、無料で作成できます

最後までスキップする

ARM テンプレートの使用に慣れている場合は、この Button to deploy the Resource Manager template to Azure. ボタンを選択して最後までスキップできます。 このボタンをクリックすると、Azure portal で ARM テンプレートが開きます。

Screenshot of the ARM Template in the Azure portal.

Azure portal で、[新規作成] を選択して新しいリソース グループを作成し、[確認と作成] ボタンを選択してアプリをデプロイします。

Azure Resource Manager テンプレート (ARM テンプレート) と Azure CLI を Cloud Shell で使用して、アプリをクラウドにデプロイすることによって、Azure App Service の使用を開始します。 Resource Manager テンプレートは JavaScript Object Notation (JSON) ファイルであり、プロジェクトのインフラストラクチャと構成が定義されています。 App Service の Free レベルを使用するため、このクイックスタートを完了するのにコストはかかりません。

このクイックスタートを完了するには、アクティブなサブスクリプションが含まれる Azure アカウントが必要です。 Azure アカウントがない場合は、無料で作成できます

最後までスキップする

ARM テンプレートの使用に慣れている場合は、この Button to deploy the Resource Manager template to Azure. ボタンを選択して最後までスキップできます。 このボタンをクリックすると、Azure portal で ARM テンプレートが開きます。

Screenshot of the ARM Template in the Azure portal.

Azure portal で、[新規作成] を選択して新しいリソース グループを作成し、[確認と作成] ボタンを選択してアプリをデプロイします。

Azure Resource Manager テンプレート (ARM テンプレート) と Azure CLI を Cloud Shell で使用して、アプリをクラウドにデプロイすることによって、Azure App Service の使用を開始します。 Resource Manager テンプレートは JavaScript Object Notation (JSON) ファイルであり、プロジェクトのインフラストラクチャと構成が定義されています。 Windows コンテナー アプリをデプロイするには、Premium プランが必要です。 価格の詳細については、「App Service の価格のページ」を参照してください。

最後までスキップする

ARM テンプレートの使用に慣れている場合は、この Button to deploy the Resource Manager template to Azure. ボタンを選択して最後までスキップできます。 このボタンをクリックすると、Azure portal で ARM テンプレートが開きます。

Screenshot of the ARM Template in the Azure portal.

Azure portal で、[新規作成] を選択して新しいリソース グループを作成し、[確認と作成] ボタンを選択してアプリをデプロイします。

テンプレートを確認する

このクイックスタートで使用されるテンプレートは Azure クイックスタート テンプレートからのものです。 これは App Service プランおよび App Service アプリを Windows にデプロイします。 .NET Core、.NET Framework、PHP、Node.js、静的 HTML アプリと互換性があります。 Java の場合は、Java アプリの作成に関する記事を参照してください。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.25.53.49325",
      "templateHash": "16144177164140676603"
    }
  },
  "parameters": {
    "webAppName": {
      "type": "string",
      "defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
      "minLength": 2,
      "metadata": {
        "description": "Web app name."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "sku": {
      "type": "string",
      "defaultValue": "F1",
      "metadata": {
        "description": "The SKU of App Service Plan."
      }
    },
    "language": {
      "type": "string",
      "defaultValue": ".net",
      "allowedValues": [
        ".net",
        "php",
        "node",
        "html"
      ],
      "metadata": {
        "description": "The language stack of the app."
      }
    },
    "helloWorld": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "true = deploy a sample Hello World app."
      }
    },
    "repoUrl": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "Optional Git Repo URL"
      }
    }
  },
  "variables": {
    "appServicePlanPortalName": "[format('AppServicePlan-{0}', parameters('webAppName'))]",
    "gitRepoReference": {
      ".net": "https://github.com/Azure-Samples/app-service-web-dotnet-get-started",
      "node": "https://github.com/Azure-Samples/nodejs-docs-hello-world",
      "php": "https://github.com/Azure-Samples/php-docs-hello-world",
      "html": "https://github.com/Azure-Samples/html-docs-hello-world"
    },
    "gitRepoUrl": "[if(bool(parameters('helloWorld')), variables('gitRepoReference')[toLower(parameters('language'))], parameters('repoUrl'))]",
    "configReference": {
      ".net": {
        "comments": ".Net app. No additional configuration needed."
      },
      "html": {
        "comments": "HTML app. No additional configuration needed."
      },
      "php": {
        "phpVersion": "7.4"
      },
      "node": {
        "appSettings": [
          {
            "name": "WEBSITE_NODE_DEFAULT_VERSION",
            "value": "12.15.0"
          }
        ]
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2023-01-01",
      "name": "[variables('appServicePlanPortalName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('sku')]"
      }
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2023-01-01",
      "name": "[parameters('webAppName')]",
      "location": "[parameters('location')]",
      "identity": {
        "type": "SystemAssigned"
      },
      "properties": {
        "siteConfig": "[variables('configReference')[parameters('language')]]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]",
        "httpsOnly": true
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]"
      ]
    },
    {
      "condition": "[contains(variables('gitRepoUrl'), 'http')]",
      "type": "Microsoft.Web/sites/sourcecontrols",
      "apiVersion": "2023-01-01",
      "name": "[format('{0}/{1}', parameters('webAppName'), 'web')]",
      "properties": {
        "repoUrl": "[variables('gitRepoUrl')]",
        "branch": "master",
        "isManualIntegration": true
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
      ]
    }
  ]
}

テンプレートでは、次の 2 つの Azure リソースが定義されています。

このテンプレートには、利便性のために事前に定義されているいくつかのパラメーターが含まれています。 パラメーターの既定値とその説明については、次のテーブルを参照してください:

パラメーター Type 既定値 説明
webAppName string webApp-<uniqueString> 一意の文字列値に基づくアプリ名
appServicePlanName string webAppPlan-<uniqueString> 一意の文字列値に基づく App Service プラン
location string [resourceGroup().location] アプリのリージョン
sku string F1 インスタンス サイズ (F1 = Free レベル)
language string .NET プログラミング言語スタック (.NET、php、node、html)
helloWorld boolean False True = "Hello World" アプリをデプロイする
repoUrl string 外部 Git リポジトリ (オプション)

このクイックスタートで使用されるテンプレートは Azure クイックスタート テンプレートからのものです。 これは App Service プランおよび App Service アプリを Linux にデプロイします。 これは App Service でサポートされているすべてのプログラミング言語と互換性があります。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.5.6.12127",
      "templateHash": "10602523904429381366"
    }
  },
  "parameters": {
    "webAppName": {
      "type": "string",
      "defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
      "minLength": 2,
      "metadata": {
        "description": "Web app name."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "sku": {
      "type": "string",
      "defaultValue": "F1",
      "metadata": {
        "description": "The SKU of App Service Plan."
      }
    },
    "linuxFxVersion": {
      "type": "string",
      "defaultValue": "DOTNETCORE|3.0",
      "metadata": {
        "description": "The Runtime stack of current web app"
      }
    },
    "repoUrl": {
      "type": "string",
      "defaultValue": " ",
      "metadata": {
        "description": "Optional Git Repo URL"
      }
    }
  },
  "variables": {
    "appServicePlanPortalName": "[format('AppServicePlan-{0}', parameters('webAppName'))]"
  },
  "resources": [
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2021-02-01",
      "name": "[variables('appServicePlanPortalName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('sku')]"
      },
      "kind": "linux",
      "properties": {
        "reserved": true
      }
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2021-02-01",
      "name": "[parameters('webAppName')]",
      "location": "[parameters('location')]",
      "properties": {
        "httpsOnly": true,
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]",
        "siteConfig": {
          "linuxFxVersion": "[parameters('linuxFxVersion')]",
          "minTlsVersion": "1.2",
          "ftpsState": "FtpsOnly"
        }
      },
      "identity": {
        "type": "SystemAssigned"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]"
      ]
    },
    {
      "condition": "[contains(parameters('repoUrl'), 'http')]",
      "type": "Microsoft.Web/sites/sourcecontrols",
      "apiVersion": "2021-02-01",
      "name": "[format('{0}/{1}', parameters('webAppName'), 'web')]",
      "properties": {
        "repoUrl": "[parameters('repoUrl')]",
        "branch": "master",
        "isManualIntegration": true
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
      ]
    }
  ]
}

テンプレートでは、次の 2 つの Azure リソースが定義されています。

このテンプレートには、利便性のために事前に定義されているいくつかのパラメーターが含まれています。 パラメーターの既定値とその説明については、次のテーブルを参照してください:

パラメーター Type 既定値 説明
webAppName string webApp-<uniqueString> 一意の文字列値に基づくアプリ名
appServicePlanName string webAppPlan-<uniqueString> 一意の文字列値に基づく App Service プラン
location string [resourceGroup().location] アプリのリージョン
sku string F1 インスタンス サイズ (F1 = Free レベル)
linuxFxVersion string DOTNETCORE|3.0 "プログラミング言語スタック | バージョン"
repoUrl string 外部 Git リポジトリ (オプション)

このクイックスタートで使用されるテンプレートは Azure クイックスタート テンプレートからのものです。 これは App Service プランおよび App Service アプリを Windows コンテナーにデプロイします。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.25.53.49325",
      "templateHash": "10193476814580854111"
    }
  },
  "parameters": {
    "appServiceWebAppName": {
      "type": "string",
      "defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
      "minLength": 2,
      "metadata": {
        "description": "Web App name."
      }
    },
    "appServicePlanName": {
      "type": "string",
      "defaultValue": "[format('webApp-{0}', uniqueString(resourceGroup().id))]",
      "minLength": 2,
      "metadata": {
        "description": "App Service Plan name."
      }
    },
    "skuTier": {
      "type": "string",
      "defaultValue": "P1v3"
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2023-01-01",
      "name": "[parameters('appServiceWebAppName')]",
      "location": "[parameters('location')]",
      "tags": {
        "[format('hidden-related:{0}', resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName')))]": "empty"
      },
      "properties": {
        "siteConfig": {
          "appSettings": [
            {
              "name": "PORT",
              "value": "8080"
            }
          ],
          "appCommandLine": "",
          "windowsFxVersion": "DOCKER|mcr.microsoft.com/dotnet/samples:aspnetapp"
        },
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
      ]
    },
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2023-01-01",
      "name": "[parameters('appServicePlanName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('skuTier')]"
      },
      "kind": "windows",
      "properties": {
        "hyperV": true
      }
    }
  ]
}

テンプレートでは、次の 2 つの Azure リソースが定義されています。

このテンプレートには、利便性のために事前に定義されているいくつかのパラメーターが含まれています。 パラメーターの既定値とその説明については、次のテーブルを参照してください:

パラメーター Type 既定値 説明
webAppName string webApp-<uniqueString> 一意の文字列値に基づくアプリ名
appServicePlanName string webAppPlan-<uniqueString> 一意の文字列値に基づく App Service プラン
location string [resourceGroup().location] アプリのリージョン
skuTier string P1v3 インスタンス サイズ (使用可能な SKU を表示)
appSettings string [{"name": "PORT","value": "8080"}] App Service リッスン ポート。 8080 である必要があります。
kind string windows オペレーティング システム
hyperv string true 分離モード
windowsFxVersion string DOCKER|mcr.microsoft.com/dotnet/samples:aspnetapp コンテナー イメージ

テンプレートのデプロイ

テンプレートをデプロイするために、ここでは Azure CLI を使用します。 Azure portal、Azure PowerShell、REST API を使用することもできます。 他のデプロイ方法については、「テンプレートのデプロイ」を参照してください。

以下のコードでは、リソース グループ、App Service プラン、Web アプリを作成します。 既定のリソース グループ、App Service プラン、場所が設定されています。 <app-name> を、グローバルに一意であるアプリ名に置き換えてください (有効な文字は、a-z0-9- です)。

次のコマンドを実行して、Windows に .NET Framework アプリをデプロイします。

az group create --name myResourceGroup --location "southcentralus"

az deployment group create --resource-group myResourceGroup \
--parameters language=".NET" helloWorld="true" webAppName="<app-name>" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-windows/azuredeploy.json"

次のコマンドを実行して、Linux 上に Python アプリを作成します:

az group create --name myResourceGroup --location "southcentralus"

az deployment group create --resource-group myResourceGroup --parameters webAppName="<app-name>" linuxFxVersion="PYTHON|3.9" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-linux/azuredeploy.json"

別の言語スタックをデプロイするには、linuxFxVersion を適切な値で更新します。 サンプルをテーブルに示します。 現在のバージョンを表示するには、Cloud Shell で次のコマンドを実行します: az webapp config show --resource-group myResourceGroup --name <app-name> --query linuxFxVersion

Language 例:
.NET linuxFxVersion="DOTNETCORE|3.0"
PHP linuxFxVersion="PHP|7.4"
Node.js linuxFxVersion="NODE|10.15"
Java linuxFxVersion="JAVA|1.8 |TOMCAT|9.0"
Python linuxFxVersion="PYTHON|3.7"

次のコマンドを実行して、.NET アプリ を Windows コンテナーにデプロイします。

az group create --name myResourceGroup --location "southcentralus"

az deployment group create --resource-group myResourceGroup \
--parameters webAppName="<app-name>" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/app-service-docs-windows-container/azuredeploy.json"

デプロイの検証

http://<app_name>.azurewebsites.net/ を参照して、作成されていることを確認します。

Screenshot of the Windows code experience.

Screenshot of the Linux experience.

Screenshot of the Windows container experience.

リソースをクリーンアップする

不要になったら、リソース グループを削除します

次のステップ

 ローカル Git からのデプロイ

 Python と Postgres