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

将计算机视觉容器部署到 Azure 容器实例Deploy the Computer Vision container to Azure Container Instances

了解如何将认知服务计算机视觉容器部署到 Azure容器实例Learn how to deploy the Cognitive Services Computer Vision container to Azure Container Instances. 此过程演示计算机视觉资源的创建。This procedure demonstrates the creation of the Computer Vision resource. 然后讨论如何拉取关联的容器映像。Then we discuss pulling the associated container image. 最后,我们重点介绍了从浏览器中执行这两个业务流程的能力。Finally, we highlight the ability to exercise the orchestration of the two from a browser. 使用容器可以将开发人员的注意力从管理基础结构转移到应用程序开发上。Using containers can shift the developers' attention away from managing infrastructure to instead focusing on application development.

必备组件Prerequisites

  • 使用 Azure 订阅。Use an Azure subscription. 如果还没有 Azure 订阅,可以在开始前创建一个 免费帐户If you don't have an Azure subscription, create a free account before you begin.
  • 安装Azure CLI (az)。Install the Azure CLI (az).
  • Docker 引擎并验证 Docker CLI 是否可在控制台窗口中工作。Docker engine and validate that the Docker CLI works in a console window.

请求访问专用容器注册表Request access to the private container registry

填写并提交认知服务影像容器请求窗体容器请求访问。Fill out and submit the Cognitive Services Vision Containers Request form to request access to the container. 通过该表单请求有关你、你的公司以及要使用该容器的用户方案的信息。The form requests information about you, your company, and the user scenario for which you'll use the container. 在提交表单后,Azure 认知服务团队会检查,以确保满足的条件访问专用容器注册表的权限。After you submit the form, the Azure Cognitive Services team reviews it to make sure that you meet the criteria for access to the private container registry.

重要

必须使用与 Microsoft 帐户 (MSA) 或窗体中的 Azure Active Directory (Azure AD) 帐户相关联的电子邮件地址。You must use an email address associated with either a Microsoft Account (MSA) or an Azure Active Directory (Azure AD) account in the form.

如果你的请求得到批准,您将收到一封电子邮件的说明介绍如何获取你的凭据和访问专用容器注册表的。If your request is approved, you receive an email with instructions that describe how to obtain your credentials and access the private container registry.

登录到专用容器注册表Log in to the private container registry

有几种方法使用认知服务容器的专用容器注册表进行身份验证。There are several ways to authenticate with the private container registry for Cognitive Services containers. 我们建议你通过使用命令行方法Docker CLIWe recommend that you use the command-line method by using the Docker CLI.

使用docker 登录名命令,如下面的示例中所示中登录到containerpreview.azurecr.io,这是专用容器注册表的认知服务容器。Use the docker login command, as shown in the following example, to log in to containerpreview.azurecr.io, which is the private container registry for Cognitive Services containers. 将 <username> 替换为用户名,将 <password> 替换为从 Azure 认知服务团队收到的凭据中提供的密码 。Replace <username> with the user name and <password> with the password provided in the credentials you received from the Azure Cognitive Services team.

docker login containerpreview.azurecr.io -u <username> -p <password>

如果你保护你的凭据在文本文件中,您可以连接到该文本文件的内容docker login命令。If you secured your credentials in a text file, you can concatenate the contents of that text file to the docker login command. 使用cat命令,如下面的示例中所示。Use the cat command, as shown in the following example. 替换 <passwordFile> 使用的路径和包含密码的文本文件的名称。Replace <passwordFile> with the path and name of the text file that contains the password. 替换 <用户名> 与你的凭据中提供的用户名称。Replace <username> with the user name provided in your credentials.

cat <passwordFile> | docker login containerpreview.azurecr.io -u <username> --password-stdin

创建计算机视觉资源Create an Computer Vision resource

  1. 登录到 Azure 门户Sign into the Azure portal.

  2. 单击 "创建计算机视觉资源"。Click Create Computer Vision resource.

  3. 输入所有必需的设置:Enter all required settings:

    设置Setting Value
    名称Name 所需名称(2-64 个字符)Desired name (2-64 characters)
    订阅Subscription 选择相应的订阅Select appropriate subscription
    位置Location 选择附近任何可用的位置Select any nearby and available location
    定价层Pricing Tier F0 - 最小定价层F0 - the minimal pricing tier
    资源组Resource Group 选择可用的资源组Select an available resource group
  4. 单击“创建”并等待创建资源。Click Create and wait for the resource to be created. 创建后,导航到 "资源" 页。After it is created, navigate to the resource page.

  5. 收集配置的 {ENDPOINT_URI}{API_KEY},请参阅收集详细信息所需的参数Collect configured {ENDPOINT_URI} and {API_KEY}, see gathering required parameters for details.

从 Azure CLI 创建 Azure 容器实例资源Create an Azure Container Instance resource from the Azure CLI

下面的 YAML 定义 Azure 容器实例资源。The YAML below defines the Azure Container Instance resource. 将内容复制并粘贴到名为my-aci.yaml的新文件中, 并用自己的值替换注释值。Copy and paste the contents into a new file, named my-aci.yaml and replace the commented values with your own. 有关有效的 YAML, 请参阅模板格式Refer to the template format for valid YAML. 有关可用映像名称及其相应的存储库, 请参阅容器存储库和映像Refer to the container repositories and images for the available image names and their corresponding repository.

apiVersion: 2018-10-01
location: # < Valid location >
name: # < Container Group name >
imageRegistryCredentials:
  - server: containerpreview.azurecr.io
    username: # < The username for the preview container registry >
    password: # < The password for the preview container registry >
properties:
  containers:
  - name: # < Container name >
    properties:
      image: # < Repository/Image name >
      environmentVariables: # These env vars are required
        - name: eula
          value: accept
        - name: billing
          value: # < Service specific Endpoint URL >
        - name: apikey
          value: # < Service specific API key >
      resources:
        requests:
          cpu: 4 # Always refer to recommended minimal resources
          memoryInGb: 8 # Always refer to recommended minimal resources
      ports:
        - port: 5000
  osType: Linux
  restartPolicy: OnFailure
  ipAddress:
    type: Public
    ports:
    - protocol: tcp
      port: 5000
tags: null
type: Microsoft.ContainerInstance/containerGroups

备注

并非所有位置都具有相同的 CPU 和内存可用性。Not all locations have the same CPU and Memory availability. 有关每个位置和 OS 的容器可用资源列表, 请参阅 "位置和资源" 表。Refer to the location and resources table for the listing of available resources for containers per location and OS.

我们将依赖于为az container create命令创建的 YAML 文件。We'll rely on the YAML file we created for the az container create command. 在 Azure CLI 中, 执行az container create命令, 将替换为你自己的。 <resource-group>From the Azure CLI, execute the az container create command replacing the <resource-group> with your own. 此外, 为了保护 YAML 部署中的值, 请参阅安全值Additionally, for securing values within a YAML deployment refer to secure values.

az container create -g <resource-group> -f my-aci.yaml

如果在某些情况下输出Running...更改为表示新创建的 ACI 资源的 JSON 字符串, 则该命令的输出为有效。The output of the command is Running... if valid, after sometime the output changes to a JSON string representing the newly created ACI resource. 容器映像不太可能在一段时间内不可用, 但现在已部署资源。The container image is more than likely not be available for a while, but the resource is now deployed.

提示

请密切注意公共预览版 Azure 认知服务产品的位置, 因为需要相应地调整 YAML 来匹配位置。Pay close attention to the locations of public preview Azure Cognitive Service offerings, as the YAML will needed to be adjusted accordingly to match the location.

验证容器是否正在运行Validate that a container is running

有几种方法可用于验证容器是否正在运行。There are several ways to validate that the container is running. 找到相关容器的外部 IP地址和公开端口, 并打开你喜欢的 web 浏览器。Locate the External IP address and exposed port of the container in question, and open your favorite web browser. 使用以下各种请求 Url 来验证容器是否正在运行。Use the various request URLs below to validate the container is running. 下面列出的示例请求 url 为http://localhost:5000, 但特定容器可能会有所不同。The example request URLs listed below are http://localhost:5000, but your specific container may vary. 请记住, 你要依赖容器的外部 IP地址和公开的端口。Keep in mind that you're to rely on your container's External IP address and exposed port.

请求 URLRequest URL 用途Purpose
http://localhost:5000/ 容器提供主页。The container provides a home page.
http://localhost:5000/status 使用 HTTP GET 请求, 用于验证容器是否正在运行而不会导致终结点查询。Requested with an HTTP GET, to validate that the container is running without causing an endpoint query. 此请求可用于 Kubernetes 运行情况和就绪情况探测This request can be used for Kubernetes liveness and readiness probes.
http://localhost:5000/swagger 该容器提供了一套完整的端点文档和一项试用功能。The container provides a full set of documentation for the endpoints and a Try it out feature. 使用此功能可以将设置输入到基于 Web 的 HTML 表单并进行查询,而无需编写任何代码。With this feature, you can enter your settings into a web-based HTML form and make the query without having to write any code. 查询返回后,将提供示例 CURL 命令,用于演示所需的 HTTP 标头和正文格式。After the query returns, an example CURL command is provided to demonstrate the HTTP headers and body format that's required.

容器的主页

后续步骤Next steps

让我们继续使用 Azure 认知服务容器。Let's continue working with Azure Cognitive Services containers.