将计算机视觉容器部署到 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 trial 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. 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.

重要

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. We recommend that you use the command-line method by using the Docker CLI.

Use the docker login command, as shown in the following example, to log in to containerpreview.azurecr.cn, which is the private container registry for Cognitive Services containers. 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.cn -u <username> -p <password>

If you secured your credentials in a text file, you can concatenate the contents of that text file to the docker login command. Use the cat command, as shown in the following example. 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.cn -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 ValueValue
    名称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. 请参阅[容器存储库和映像][repositories-and-images],获取可用的映像名称及其相应的存储库。Refer to the [container repositories and images][repositories-and-images] for the available image names and their corresponding repository. 有关容器实例的 YAML 引用的详细信息,请参阅 [YAML 引用:Azure 容器实例][aci-yaml-ref]。For more information of the YAML reference for Container instances, see [YAML reference: Azure Container Instances][aci-yaml-ref].

apiVersion: 2018-10-01
location: # < Valid location >
name: # < Container Group name >
imageRegistryCredentials: # This is required when pulling a non-public image
  - 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
  volumes: # This node, is only required for container instances that pull their model in at runtime, such as LUIS.
  - name: aci-file-share
    azureFile:
      shareName: # < File share name >
      storageAccountName: # < Storage account name>
      storageAccountKey: # < Storage account key >
  restartPolicy: OnFailure
  ipAddress:
    type: Public
    ports:
    - protocol: tcp
      port: 5000
tags: null
type: Microsoft.ContainerInstance/containerGroups
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.

容器的主页