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

使用用于 IntelliJ 的 Azure 工具包将 Hello World Web 应用部署到云中的 Linux 容器Deploy a Hello World web app to a Linux container in the cloud using the Azure Toolkit for IntelliJ

Docker 容器广泛用于部署 Web 应用程序。Docker containers are a widely used method for deploying web applications. 开发人员可在其中将其所有项目文件和依赖项整合成单个包,以便部署到服务器。By using Docker containers, developers can consolidate all their project files and dependencies into a single package for deployment to a server. 用于 IntelliJ 的 Azure 工具包可以添加用于将容器部署到 Microsoft Azure 的功能,为 Java 开发人员简化了部署过程。The Azure Toolkit for IntelliJ simplifies this process for Java developers by adding features for to deploy containers to Microsoft Azure.

本文演示如何创建基本的 Hello World Web 应用和使用用于 IntelliJ 的 Azure 工具包将 Linux 容器中的 Web 应用发布到 Azure。This article demonstrates the steps that are required to create a basic Hello World web app and publish your web app in a Linux container to Azure by using the Azure Toolkit for IntelliJ.

先决条件Prerequisites

若要完成文章中的步骤,需要安装用于 IntelliJ 的 Azure 工具包,该工具包需要以下软件组件:To complete the steps in his article, you will need to install the Azure Toolkit for IntelliJ, which requires the following software components:

  • IntelliJ IDEA 旗舰版或社区版,可从 JetBrains 网站下载。IntelliJ IDEA Ultimate Edition or Community Edition, which can be downloaded from the JetBrains website.

  • 一个受支持的 Java 开发工具包 (JDK)。A supported Java Development Kit (JDK). 有关在 Azure 上进行开发时可供使用的 JDK 的详细信息,请参阅 https://aka.ms/azure-jdksFor more information about the JDKs available for use when developing on Azure, see https://aka.ms/azure-jdks.

  • 操作系统。An operating system. 用于 IntelliJ 的 Azure 工具包已在以下操作系统上通过测试:The Azure Toolkit for IntelliJ has been tested on the following operating systems:

    • Windows 10、Windows 8.1、Windows 8 和 Windows 7Windows 10, Windows 8.1, Windows 8, and Windows 7
    • Windows Server 2012 R2、Windows Server 2012、Windows Server 2008 R2 和 Windows Server 2008Windows Server 2012 R2, Windows Server 2012, Windows Server 2008 R2, and Windows Server 2008
    • Mac OS X 版本“Yosemite”及更高版本Mac OS X version "Yosemite" and later
    • Ubuntu Linux 版本 14、15 和 16Ubuntu Linux version 14, 15, and 16

备注

JetBrains 插件存储库中的 Azure Toolkit for IntelliJ 页列出了与该工具包兼容的内部版本。The Azure Toolkit for IntelliJ page at the JetBrains Plugin Repository lists the builds that are compatible with the toolkit.

备注

若要完成本教程中的步骤,需要将 Docker 配置为在不具备 TLS 的情况下在端口 2375 上公开守护程序。To complete the steps in this tutorial, you need to configure Docker to expose the daemon on port 2375 without TLS. 可在安装 Docker 时配置此设置,或通过 Docker 设置菜单进行配置。You can configure this setting when installing Docker, or through the Docker settings menu.

Docker 设置菜单

创建新 Web 应用项目Create a new web app project

  1. 启动 IntelliJ,并按照用于 IntelliJ 的 Azure 工具包的登录说明一文中的步骤登录 Azure 帐户。Start IntelliJ and sign in to your Azure account using the steps in the Sign In Instructions for the Azure Toolkit for IntelliJ article.

  2. 依次单击“文件”菜单、“新建”、“项目”。Click the File menu, then click New, and then click Project.

    创建新项目

  3. 在“新建项目”对话框中,选择 Maven,然后选择 maven-archetype-webapp,然后单击“下一步”。In the New Project dialog box, select Maven, then maven-archetype-webapp, and then click Next.

    选择 Maven archetype webapp

  4. 为 Web 应用指定 GroupId 和 ArtifactId,然后单击“下一步”。Specify the GroupId and ArtifactId for your web app, and then click Next.

    指定 GroupId 和 ArtifactId

  5. 自定义任何 Maven 设置或接受默认设置,然后单击“下一步”。Customize any Maven settings or accept the defaults, and then click Next.

    指定 Maven 设置

  6. 指定项目名称和位置,并单击“完成”。Specify your project name and location, and then click Finish.

    指定项目名称

创建 Azure 容器注册表,用作专用 Docker 注册表Create an Azure Container Registry to use as a private Docker registry

以下步骤将引导你完成使用 Azure 门户来创建 Azure 容器注册表的步骤。The following steps walk you through using the Azure portal to create an Azure Container Registry.

备注

如果想要使用 Azure CLI(而不是 Azure 门户),请按照使用 Azure CLI 2.0 创建专用 Docker 容器注册表中的步骤操作。If you want to use the Azure CLI instead of the Azure portal, follow the steps in Create a private Docker container registry using the Azure CLI 2.0.

  1. 浏览到 Azure 门户并登录。Browse to the Azure portal and sign in.

    登录到你在 Azure 门户的帐户后,可以按照使用 Azure 门户创建专用 Docker 容器注册表一文中的步骤操作,为方便起见,在以下步骤中进行了解释。Once you have signed in to your account on the Azure portal, you can follow the steps in the Create a private Docker container registry using the Azure portal article, which are paraphrased in the following steps for the sake of expediency.

  2. 依次单击“+ 创建资源”菜单图标、“容器”、“容器注册表”。Click the menu icon for + Create a resource, then click Containers, and then click Container Registry.

    创建新的 Azure 容器注册表

  3. 当显示“创建容器注册表”页时,输入你的“注册表名称”和“资源组”,为“管理员用户”选择“启用”,然后单击“创建”。When the Create container registry page is displayed, enter your Registry name and Resource group, choose Enable for the Admin user, and then click Create.

    配置 Azure 容器注册表设置

在 Docker 容器中部署 Web 应用Deploy your web app in a Docker container

  1. 右键单击项目资源管理器中的项目,选择“Azure”,然后单击“添加 Docker 支持”。Right-click your project in the project explorer, choose Azure, and then click Add Docker Support.

    将使用默认配置自动创建 Docker 文件。This will automatically create a Docker file with a default configuration.

    添加 Docker 支持

  2. 添加 Docker 支持后,右键单击项目资源管理器中的项目,选择“Azure”,然后单击“在用于容器的 Web 应用上运行”。After you have added Docker support, right-click your project in the project explorer, choose Azure, and then click Run on Web App for Containers.

    在用于容器的 Web 应用上运行

  3. 显示“在用于容器的 Web 应用上运行”对话框时,填写必要信息:When the Run on Web App for Containers dialog box is displayed, fill in the requisite information:

    • 名称:指定在 Azure Toolkit 中显示的易记名称。Name: This specifies the friendly name which is displayed in the Azure Toolkit.

    • 容器注册表:从下拉菜单中选择在本文的上一部分创建的容器注册表。Container Registry: Choose the container registry from the drop-down menu that you created in the previous section of this article. “服务器 URL”、“用户名”和“密码”字段会自动填充。The fields for Server URL, Username, and Password will be automatically populated.

    • 映像和标记:指定容器映像名称;通常使用以下语法:“registry.azurecr.io/appname:latest”,其中:Image and tag: Specifies the container image name; typically this will use the following syntax: "registry.azurecr.io/appname:latest", where:

      • 注册表是上文所述的容器注册表registry is your container registry from the previous section of this article
      • appname 是 Web 应用的名称appname is the name of your web app
    • 使用现有的 Web 应用创建新的 Web 应用:指定是将容器部署到现有 Web 应用还是创建新的 Web 应用。Use Existing Web App or Create New Web App: Specifies whether you will deploy your container to an existing web app or create a new web app. 指定的“应用名称”将创建 Web 应用的 URL,例如 wingtiptoys.azurewebsites.netThe App name that you specify will create the URL for your web app; for example: wingtiptoys.azurewebsites.net.

    • 资源组:指定是要使用现有资源组还是创建新的资源组。Resource Group: Specifies whether you will use an existing or create a new resource group.

    • 应用服务计划:指定是要使用现有应用服务计划还是创建新的应用服务计划。App Service Plan: Specifies whether you will use an existing or create a new app service plan.

    在用于容器的 Web 应用上运行

  4. 配置完上面列出的设置后,单击“运行”。When you have finished configuring the settings listed above, click Run. 成功部署 Web 应用以后,状态会显示在“运行”窗口中。When your web app has been successfully deployed, the status will be displayed in the Run window.

    成功部署的 Web 应用

  5. 发布 Web 应用以后,即可浏览到此前为 Web 应用指定的 URL,例如 wingtiptoys.azurewebsites.netAfter your web app has been published, you can browse to the URL that specifed earlier for your web app; for example: wingtiptoys.azurewebsites.net.

    浏览到 Web 应用

可选:修改 Web 应用发布设置Optional: Modify your web app publish settings

  1. 发布 Web 应用后,所做设置会保存为默认设置,可单击工具栏上的绿色箭头图标在 Azure 上运行应用程序。After you have published your web app, your settings will be saved as the default, and you can run your application on Azure by clicking the green arrow icon on the toolbar. 可通过单击 Web 应用的下拉菜单来修改这些设置,然后单击“编辑配置”。You can modify these settings by clicking the drop-down menu for your web app and click Edit Configurations.

    “编辑配置”菜单

  2. 出现“运行/调试配置”对话框后,可修改任意默认设置,然后单击“确定”。When the Run/Debug Configurations dialog box is displayed, you can modify any of the default settings, and then click OK.

    “编辑配置”对话框

后续步骤Next steps

有关 Docker 的其他资源,请参阅官方 Docker 网站For additional resources for Docker, see the official Docker website.

有关用于 IntelliJ IDEA 的 Azure 工具包的详细信息,请参阅以下链接:For more information about the Azure Toolkit for IntelliJ IDEA, see the following links:

若要详细了解如何将 Java 与 Azure 配合使用,请参阅以下链接:For more information about using Java with Azure, see the following links:

[Get Java JDK downloads and support when developing for Azure](https://aka.ms/azure-jdks)