您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

将自定义 Linux 容器部署到 Azure 应用服务Deploy a custom Linux container to Azure App Service

Linux 上的应用服务在 Linux 上提供预定义的应用程序堆栈,并支持特定语言,例如 .NET、PHP、Node.js 等。App Service on Linux provides pre-defined application stacks on Linux with support for languages such as .NET, PHP, Node.js and others. 还可使用自定义 Docker 映像,于尚未在 Azure 中定义的应用程序堆栈中运行 Web 应用。You can also use a custom Docker image to run your web app on an application stack that is not already defined in Azure. 本快速入门介绍如何将Azure 容器注册表 (ACR) 中的映像部署到应用服务。This quickstart shows you how to deploy an image from an Azure Container Registry (ACR) to App Service.

先决条件Prerequisites

创建映像Create an image

若要完成本快速入门,需要在 Azure 容器注册表中存储合适的 Web 应用映像。To complete this quickstart, you will need a suitable web app image stored in an Azure Container Registry. 遵循快速入门:使用 Azure 门户创建专用容器注册表中的说明进行操作,但使用 mcr.microsoft.com/azuredocs/go 映像而不是 hello-world 映像。Follow the instructions in Quickstart: Create a private container registry using the Azure portal, but use the mcr.microsoft.com/azuredocs/go image instead of the hello-world image. 若要参考,可在 Azure 示例存储库中找到示例 DockerfileFor reference, the sample Dockerfile is found in Azure Samples repo.

重要

请确保在创建容器注册表时将“管理员用户” 选项设为“启用” 。Be sure to set the Admin User option to Enable when you create the container registry. 也可以在 Azure 门户中从注册表页的“访问密钥” 部分进行设置。You can also set it from the Access keys section of your registry page in the Azure portal. 应用服务访问需要此设置。This setting is required for App Service access.

登录Sign in

接下来,使用应用服务扩展启动 VS Code 并登录到 Azure 帐户。Next, launch VS Code and log into your Azure account using the App Service extension. 为此,请在活动栏中选择 Azure 徽标,导航到“应用服务” 资源管理器,然后选择“登录到 Azure” ,并按照说明进行操作。To do this, select the Azure logo in the Activity Bar, navigate to the APP SERVICE explorer, then select Sign in to Azure and follow the instructions.

登录到 Azure

检查先决条件Check prerequisites

现在你可以检查是否已安装并配置了所有必备组件。Now you can check whether you have all the prerequisites installed and configured properly.

在 VS Code 的状态栏中应会显示你的 Azure 电子邮件地址,“应用服务”资源管理器中应会显示你的订阅。 In VS Code, you should see your Azure email address in the Status Bar and your subscription in the APP SERVICE explorer.

接下来,验证是否已安装并运行 Docker。Next, verify that you have Docker installed and running. 以下命令将显示 Docker 版本(如果它正在运行)。The following command will display the Docker version if it is running.

docker --version

最后,请确保已连接 Azure 容器注册表。Finally, ensure that your Azure Container Registry is connected. 为此,请在活动栏中选择 Docker 徽标,然后导航到“注册表” 。To do this, select the Docker logo in the Activity Bar, then navigate to REGISTRIES.

注册表

将映像部署到 Azure 应用服务Deploy the image to Azure App Service

完成所有配置后,即可将映像直接从 Docker 扩展资源管理器部署到 Azure 应用服务Now that everything is configured, you can deploy your image to Azure App Service directly from the Docker extension explorer.

DOCKER 资源管理器中的“注册表” 节点下找到映像,并将其展开以显示其标记。Find the image under the Registries node in the DOCKER explorer, and expand it to show its tags. 右键单击标记,然后选择“将映像部署到 Azure 应用服务” 。Right-click a tag and then select Deploy Image to Azure App Service.

在此处,按照提示选择订阅、全局唯一的应用名称、资源组和应用服务计划。From here, follow the prompts to choose a subscription, a globally unique app name, a Resource Group, and an App Service Plan. 选择“B1 基本” 作为“定价层”,并选择区域。Choose B1 Basic for the pricing tier, and a region.

部署之后,你的应用将在 http://<app name>.azurewebsites.net 上可用。After deployment, your app is available at http://<app name>.azurewebsites.net.

“资源组” 是 Azure 中所有应用程序资源的命名集合。A Resource Group is a named collection of all your application's resources in Azure. 例如,资源组可以包含对网站、数据库和 Azure 函数的引用。For example, a Resource Group can contain a reference to a website, a database, and an Azure Function.

应用服务计划 定义用于托管网站的物理资源。An App Service Plan defines the physical resources that will be used to host your website. 此快速入门在 Linux 基础结构上使用 “基本”托管计划,这意味着该站点将与其他网站一起托管在 Linux 计算机上。This quickstart uses a Basic hosting plan on Linux infrastructure, which means the site will be hosted on a Linux machine alongside other websites. 如果开始使用“基本” 计划,则可以使用 Azure 门户进行扩展,使你的计算机是在计算机上运行的唯一站点。If you start with the Basic plan, you can use the Azure portal to scale up so that yours is the only site running on a machine.

浏览网站Browse the website

“输出” 面板将在部署过程中打开,以指示操作的状态。The Output panel will open during deployment to indicate the status of the operation. 操作完成后,查找在“应用服务” 资源管理器中创建的应用,右键单击该应用,然后选择“浏览网站” 以在浏览器中打开该站点。When the operation completes, find the app you created in the APP SERVICE explorer, right-click it, then select Browse Website to open the site in your browser.

后续步骤Next steps

祝贺你,你现已成功完成本快速入门!Congratulations, you've successfully completed this quickstart!

接下来请查看其他 Azure 扩展。Next, check out the other Azure extensions.

或安装 Azure 工具扩展包获取所有这些工具。Or get them all by installing the Azure Tools extension pack.