部署和 Azure 容器執行個體上執行容器Deploy and run container on Azure Container Instance

使用下列步驟中,調整在雲端中輕鬆地使用 Azure 的 Azure 認知服務應用程式容器執行個體With the following steps, scale Azure Cognitive Services applications in the cloud easily with Azure Container Instance. 本文協助您專注於建置您的應用程式,而不是管理基礎結構中。This helps you focus on building your applications instead of managing the infrastructure.

先決條件Prerequisites

此解決方案適用於任何認知服務容器。This solution works with any Cognitive Services container. 認知服務資源必須建立在 Azure 入口網站,才能使用此配方。The Cognitive Service resource must be created in the Azure portal before using this recipe. 每個支援容器的認知服務有特別針對安裝和設定容器服務的 < 如何安裝 > 文件。Each Cognitive Service that supports containers has a "How to install" document specifically for installing and configuring the service for a container. 因為某些服務需要檔案或一組檔案,做為容器的輸入時,很重要,您會了解,並以前用過容器已成功使用此解決方案。Because some services require a file or set of files as input for the container, it is important that you understand and have used the container successfully before using this solution.

  • 在 Azure 入口網站中建立認知服務資源。A Cognitive Service resource, created in Azure portal.
  • 認知服務端點 URL -檢閱您特定服務的 「 如何安裝 」 容器的內容,若要尋找其中的端點 URL 是從 Azure 入口網站中,以及正確的範例,該 url 看起來像。Cognitive Service endpoint URL - review your specific service's "How to install" for the container, to find where the endpoint URL is from within the Azure portal, and what a correct example of the URL looks like. 確切的格式可以變更的服務。The exact format can change from service to service.
  • 認知服務金鑰-機碼位於金鑰Azure 資源的頁面。Cognitive Service key - the keys are on the Keys page for the Azure resource. 您只需要兩個金鑰中的其中一個。You only need one of the two keys. 此金鑰是 32 個英數字元字串。The key is a string of 32 alpha-numeric characters.
  • 單一認知服務上的容器本機主機 (您的電腦)。A single Cognitive Services Container on your local host (your computer). 請確定您可以:Make sure you can:
    • 提取映像docker pull命令。Pull down the image with a docker pull command.
    • 使用具有所有必要的組態設定已成功執行本機容器docker run命令。Run the local container successfully with all required configuration settings with a docker run command.
    • 呼叫容器的端點,取回 2xx 回應和 JSON 回應。Call the container's endpoint, getting a response of 2xx and a JSON response back.

角括弧中的所有變數<>,需要換成您自己的值。All variables in angle brackets, <>, need to be replaced with your own values. 這項取代包含角括號。This replacement includes the angle brackets.

建立 Azure 容器實例資源Create an Azure Container Instance resource

  1. 移至容器實例的 [建立] 頁面。Go to the Create page for Container Instances.

  2. 在 [基本] 索引標籤上, 輸入下列詳細資料:On the Basics tab, enter the following details:

    設定Setting Value
    訂閱Subscription 選取您的訂用帳戶。Select your subscription.
    資源群組Resource group 選取可用的資源群組, 或建立一個新的, cognitive-services例如。Select the available resource group or create a new one such as cognitive-services.
    容器名稱Container name 輸入名稱, 例如cognitive-container-instanceEnter a name such as cognitive-container-instance. 名稱必須是小寫。The name must be in lower caps.
    LocationLocation 選取要部署的區域。Select a region for deployment.
    映像類型Image type 如果您的容器映射儲存在不需要認證的容器登錄中, 請Public選擇 []。If your container image is stored in a container registry that doesn’t require credentials, choose Public. 如果存取您的容器映射需要認證, Private請選擇 []。If accessing your container image requires credentials, choose Private. 如需容器映射是PublicPrivate (「公開預覽」) 的詳細資訊, 請參閱容器存放庫和映射Refer to container repositories and images for details on whether or not the container image is Public or Private ("Public Preview").
    映像名稱Image name 輸入認知服務容器位置。Enter the Cognitive Services container location. 位置是用來docker pull做為命令引數的位置。The location is what's used as an argument to the docker pull command. 請參閱容器存放庫和映射, 以取得可用映射名稱及其對應的儲存機制。Refer to the container repositories and images for the available image names and their corresponding repository.

    映射名稱必須是完整的指定三個部分。The image name must be fully qualified specifying three parts. 首先, 容器登錄, 然後是存放庫, 最後是映射名稱: <container-registry>/<repository>/<image-name>First, the container registry, then the repository, finally the image name: <container-registry>/<repository>/<image-name>.

    以下是範例, mcr.microsoft.com/azure-cognitive-services/keyphrase其代表 Azure 認知服務存放庫下 Microsoft Container Registry 中的關鍵片語擷取映射。Here is an example, mcr.microsoft.com/azure-cognitive-services/keyphrase would represent the Key Phrase Extraction image in the Microsoft Container Registry under the Azure Cognitive Services repository. 另一個範例是containerpreview.azurecr.io/microsoft/cognitive-services-speech-to-text , 它代表容器預覽容器登錄的 Microsoft 存放庫中的語音轉換文字映射。Another example is, containerpreview.azurecr.io/microsoft/cognitive-services-speech-to-text which would represent the Speech to Text image in the Microsoft repository of the Container Preview container registry.
    OS 類型OS type Linux
    SizeSize 針對您特定的認知服務容器, 將大小變更為建議的建議:Change size to the suggested recommendations for your specific Cognitive Service container:
    2個 CPU 核心2 CPU cores
    4 GB4 GB
  3. 在 [網路功能] 索引標籤上, 輸入下列詳細資料:On the Networking tab, enter the following details:

    設定Setting Value
    連接埠Ports 將 TCP 埠設定為5000Set the TCP port to 5000. 公開端口5000上的容器。Exposes the container on port 5000.
  4. 在 [ Advanced ] 索引標籤上, 為 Azure 容器實例資源的容器帳單設定輸入必要的環境變數:On the Advanced tab, enter the required Environment Variables for the container billing settings of the Azure Container Instance resource:

    KeyKey Value
    apikey 從資源的 [金鑰] 頁面複製。Copied from the Keys page of the resource. 它是32英數位元字串, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx不含空格或連字號。It is a 32 alphanumeric-character string with no spaces or dashes, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
    billing 從資源的 [總覽] 頁面複製的。Copied from the Overview page of the resource.
    eula accept
  5. 按一下 [審查並建立]Click Review and Create

  6. 通過驗證之後, 按一下 [建立] 以完成建立程式After validation passes, click Create to finish the creation process

  7. 當資源部署成功時, 即已準備就緒When the resource is successfully deployed, it's ready

使用容器執行個體Use the Container Instance

  1. 選取 概觀並複製 IP 位址。Select the Overview and copy the IP address. 它會是數字的 IP 位址,例如55.55.55.55It will be a numeric IP address such as 55.55.55.55.

  2. 開啟新的瀏覽器索引標籤,並使用的 IP 位址,例如http://<IP-address>:5000 (http://55.55.55.55:5000)。Open a new browser tab and use the IP address, for example, http://<IP-address>:5000 (http://55.55.55.55:5000). 您會看到容器的首頁上,讓您知道容器正在執行。You will see the container's home page, letting you know the container is running.

  3. 選取 服務的 API 描述來檢視容器的 swagger 頁面。Select Service API Description to view the swagger page for the container.

  4. 選取任一POST Api,然後選取試試看。參數會顯示包括輸入。Select any of the POST APIs and select Try it out. The parameters are displayed including the input. 填入的參數。Fill in the parameters.

  5. 選取 Execute將要求傳送到您的容器執行個體。Select Execute to send the request to your Container Instance.

    您已成功建立和 Azure 容器執行個體中使用認知服務容器。You have successfully created and used Cognitive Services containers in Azure Container Instance.