教程:通过异地复制的 Azure 容器注册表部署 Web 应用Tutorial: Deploy a web app from a geo-replicated Azure container registry

本文是由三个部分构成的教程系列的第二部分。This is part two in a three-part tutorial series. 第一部分中,已创建一个专用的异地复制容器注册表,已从源生成容器映像并将其推送到该注册表。In part one, a private, geo-replicated container registry was created, and a container image was built from source and pushed to the registry. 本文通过将容器部署到位于两个不同 Azure 区域的两个 Web 应用实例中,以利用异地复制注册表的“临近网络”特点。In this article, you take advantage of the network-close aspect of the geo-replicated registry by deploying the container to Web App instances in two different Azure regions. 然后,每个实例从最近的注册表中提取容器映像。Each instance then pulls the container image from the closest registry.

本教程(教程系列的第二部分)的内容包括:In this tutorial, part two in the series:

  • 将容器映像部署到两个用于容器的 Web 应用实例 Deploy a container image to two Web Apps for Containers instances
  • 验证已部署的应用程序Verify the deployed application

如果尚未创建异地复制的注册表并将容器化示例应用程序的映像推送到注册表,请返回本教程系列的前一篇教程:准备异地复制的 Azure 容器注册表If you haven't yet created a geo-replicated registry and pushed the image of the containerized sample application to the registry, return to the previous tutorial in the series, Prepare a geo-replicated Azure container registry.

在本系列的下一篇文章中,我们将会更新该应用程序,然后将更新的容器映像推送到注册表。In the next article in the series, you update the application, then push the updated container image to the registry. 最后,浏览到每个正在运行的 Web 应用实例,以查看所做的更改是否自动反映在这两个实例中,并查看 Azure 容器注册表异地复制和 Webhook 的运行情况。Finally, you browse to each running Web App instance to see the change automatically reflected in both, showing Azure Container Registry geo-replication and webhooks in action.

自动部署到用于容器的 Web 应用Automatic deployment to Web Apps for Containers

Azure 容器注册表支持直接将容器化应用程序部署到用于容器的 Web 应用Azure Container Registry provides support for deploying containerized applications directly to Web Apps for Containers. 在本教程中,我们使用 Azure 门户将前一篇教程中创建的容器映像部署到位于不同 Azure 区域中的两个 Web 应用计划。In this tutorial, you use the Azure portal to deploy the container image created in the previous tutorial to two web app plans located in different Azure regions.

如果通过注册表中的容器映像部署 Web 应用,并且同一区域中有一个异地复制的注册表,则 Azure 容器注册表会创建一个映像部署 WebhookWhen you deploy a web app from a container image in your registry, and you have a geo-replicated registry in the same region, Azure Container Registry creates an image deployment webhook for you. 将新映像推送到容器存储库时,该 Webhook 会拾取更改,并自动将新容器映像部署到 Web 应用。When you push a new image to your container repository, the webhook picks up the change and automatically deploys the new container image to your web app.

部署用于容器的 Web 应用实例Deploy a Web App for Containers instance

此步骤在“中国北部”区域创建一个用于容器的 Web 应用实例。**In this step, you create a Web App for Containers instance in the China North region.

登录到 Azure 门户,并导航到在前一篇教程中创建的注册表。Sign in to the Azure portal and navigate to the registry you created in the previous tutorial.

选择“存储库” > “acr-helloworld”,右键单击“标记”下的“v1”标记,并选择“部署到 Web 应用” :Select Repositories > acr-helloworld, then right-click on the v1 tag under Tags and select Deploy to web app:

在 Azure 门户中部署到应用服务

如果“部署到 Web 应用”已禁用,则可能未按照第一个教程的创建容器注册表中的指示启用注册表管理员用户。If "Deploy to web app" is disabled, you might not have enabled the registry admin user as directed in Create a container registry in the first tutorial. 可以在 Azure 门户的“设置” > “访问密钥” 中启用管理员用户。You can enable the admin user in Settings > Access keys in the Azure portal.

在选择“部署到 Web 应用”后显示的“容器的 Web 应用” 下,为每项设置指定以下值:Under Web App for Containers that's displayed after you select "Deploy to web app," specify the following values for each setting:

设置Setting Value
站点名称Site Name Web 应用的全局唯一名称。A globally unique name for the web app. 本示例使用格式 <acrName>-chinanorth 来方便标识注册表,以及要从中部署 Web 应用的区域。In this example, we use the format <acrName>-chinanorth to easily identify the registry and region the web app is deployed from.
资源组Resource Group 使用现有项 > myResourceGroupUse existing > myResourceGroup
应用服务计划/位置App service plan/Location 在“中国北部”区域创建名为 plan-chinanorth 的新计划。****Create a new plan named plan-chinanorth in the China North region.
图像Image acr-helloworld:v1
操作系统Operating system LinuxLinux

备注

创建新的应用服务计划以部署容器化应用时,会自动选择默认计划以托管应用程序。When you create a new app service plan to deploy your containerized app, a default plan is automatically selected to host your application. 默认计划取决于操作系统设置。The default plan depends on the operating system setting.

选择“创建”,将 Web 应用预配到“中国北部”区域。******Select Create to provision the web app to the China North region.

Azure 门户中的“Linux 上的 Web 应用”配置

查看已部署的 Web 应用View the deployed web app

部署完成后,可在浏览器中导航到应用程序的 URL 来查看正在运行的应用程序。When deployment is complete, you can view the running application by navigating to its URL in your browser.

在门户中选择“应用服务”,再选择在上一步骤中预配的 Web 应用。 In the portal, select App Services, then the web app you provisioned in the previous step. 在本示例中,该 Web 应用名为 uniqueregistryname-chinanorthIn this example, the web app is named uniqueregistryname-chinanorth.

在“应用服务”概述的右上方选择该 Web 应用的超链接 URL,在浏览器中查看正在运行的应用程序 。Select the hyperlinked URL of the web app in the top-right of the App Service overview to view the running application in your browser.

Azure 门户中的“Linux 上的 Web 应用”配置

从异地复制的容器注册表部署 Docker 映像后,站点会显示一个图像,表示托管容器注册表的 Azure 区域。Once the Docker image is deployed from your geo-replicated container registry, the site displays an image representing the Azure region hosting the container registry.

在浏览器中查看已部署的 Web 应用程序

部署第二个用于容器的 Web 应用实例Deploy second Web App for Containers instance

使用上一部分中所述的过程,将第二个 Web 应用部署到“中国东部”区域。**Use the procedure outlined in the previous section to deploy a second web app to the China East region. 在“容器的 Web 应用”下,指定以下值 :Under Web App for Containers, specify the following values:

设置Setting Value
站点名称Site Name Web 应用的全局唯一名称。A globally unique name for the web app. 本示例使用格式 <acrName>-chinaeast 来方便标识注册表,以及要从中部署 Web 应用的区域。In this example, we use the format <acrName>-chinaeast to easily identify the registry and region the web app is deployed from.
资源组Resource Group 使用现有项 > myResourceGroupUse existing > myResourceGroup
应用服务计划/位置App service plan/Location 在“中国东部”区域创建名为 plan-chinaeast 的新计划。****Create a new plan named plan-chinaeast in the China East region.
图像Image acr-helloworld:v1
操作系统Operating system LinuxLinux

选择“创建”,将 Web 应用预配到“中国东部”区域。******Select Create to provision the web app to the China East region.

Azure 门户中的“Linux 上的 Web 应用”配置

查看已部署的 Web 应用View the deployed web app

如前所述,可在浏览器中导航到应用程序的 URL 来查看正在运行的应用程序。As before, you can view the running application by navigating to its URL in your browser.

在门户中选择“应用服务”,再选择在上一步骤中预配的 Web 应用。 In the portal, select App Services, then the web app you provisioned in the previous step. 在本示例中,该 Web 应用名为 uniqueregistryname-chinaeastIn this example, the web app is named uniqueregistryname-chinaeast.

在“应用服务概述”的右上角选择该 Web 应用的超链接 URL,在浏览器中查看正在运行的应用程序。 Select the hyperlinked URL of the web app in the top-right of the App Service overview to view the running application in your browser.

Azure 门户中的“Linux 上的 Web 应用”配置

从异地复制的容器注册表部署 Docker 映像后,站点会显示一个图像,表示托管容器注册表的 Azure 区域。Once the Docker image is deployed from your geo-replicated container registry, the site displays an image representing the Azure region hosting the container registry.

在浏览器中查看已部署的 Web 应用程序

后续步骤Next steps

本教程已从异地复制的 Azure 容器注册表部署了两个用于容器的 Web 应用实例。In this tutorial, you deployed two Web App for Containers instances from a geo-replicated Azure container registry.

请继续学习下一篇教程更新容器映像,将新的容器映像部署到容器注册表,然后验证两个区域中运行的 Web 应用是否已自动更新。Advance to the next tutorial to update and then deploy a new container image to the container registry, then verify that the web apps running in both regions were updated automatically.