你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
本文介绍如何部署多个 Azure AI 容器。 具体而言,其中将会介绍如何使用 Docker Compose 来协调单个主计算机上的多个 Docker 容器映像。 本文中的示例一起部署了文档智能容器和 AI 视觉读取容器。
注意
Docker Compose 是用于定义和运行多容器 Docker 应用程序的工具。 在 Compose 中,可以使用 YAML 文件来配置应用程序的服务。 然后,运行一条命令,从配置中创建并启动所有服务。
Prerequisites
此过程要求必须在本地安装和运行多个工具:
- Azure 订阅。 如果还没有该订阅,可以在开始前创建一个免费帐户。
- Docker 引擎。 确认 Docker CLI 是否可在控制台窗口中工作。
- 具有适当定价层的 Azure 资源。 只有以下定价层适用于此容器:
- 仅限于 F0 或标准定价层的 Foundry Tools 中的 Azure 视觉资源。
- 仅限使用 F0 或标准定价层的文档智能资源。
- Foundry Tools 资源,定价层为 S0。
- 如果使用的是门控预览版容器,则需要填写在线申请表才能使用它。
Docker Compose 文件
YAML 文件定义要部署的所有 Foundry 工具容器。 这些服务依赖于 DockerFile 或现有的容器映像。 在这种情况下,我们将使用两个映像。 复制并粘贴以下 YAML 文件,并将其保存为 docker-compose.yaml。 在文件中提供适当的 apikey、billing 和 EndpointUri 值。
重要说明
请务必在 volumes 节点下指定的主机上创建目录,或提供你的计算机上存在的目录。 这些目录必须在尝试使用卷绑定装载映像之前存在。
version: '3.7'
services:
forms:
image: "mcr.microsoft.com/azure-cognitive-services/form-recognizer/layout-3.1:latest"
environment:
eula: accept
billing: # < Your Document Intelligence billing URL >
apikey: # < Your Document Intelligence API key >
FormRecognizer__ComputerVisionApiKey: # < Your Document Intelligence API key >
FormRecognizer__ComputerVisionEndpointUri: # < Your Document Intelligence URI >
volumes:
- type: bind
source: E:\mydirectory\output
target: /output
- type: bind
source: E:\mydirectory\input
target: /input
ports:
- "5010:5000"
ocr:
image: "mcr.microsoft.com/azure-cognitive-services/vision/read:latest"
environment:
eula: accept
apikey: # < Your Vision API key >
billing: # < Your Vision billing URL >
ports:
- "5021:5000"
启动已配置的 Docker Compose 服务
使用 Docker Compose 文件可以管理所定义服务的生命周期中的所有阶段:启动、停止和重新生成服务;查看服务状态;日志流式处理。 从项目目录(docker-compose.yaml 文件所在的位置)打开命令行接口。
在命令行接口中执行以下命令,以启动(或重启)docker-compose.yaml 文件中定义的所有服务:
docker-compose up
当 Docker 首次使用此配置执行 docker-compose up 命令时,它将提取 services 节点下配置的映像,然后下载并装载这些映像:
Pulling forms (mcr.microsoft.com/azure-cognitive-services/form-recognizer/layout:)...
latest: Pulling from azure-cognitive-services/form-recognizer/layout
743f2d6c1f65: Pull complete
72befba99561: Pull complete
2a40b9192d02: Pull complete
c7715c9d5c33: Pull complete
f0b33959f1c4: Pull complete
b8ab86c6ab26: Pull complete
41940c21ed3c: Pull complete
e3d37dd258d4: Pull complete
cdb5eb761109: Pull complete
fd93b5f95865: Pull complete
ef41dcbc5857: Pull complete
4d05c86a4178: Pull complete
34e811d37201: Pull complete
Pulling ocr (mcr.microsoft.com/azure-cognitive-services/vision/read:3.1-preview:)...
latest: Pulling from /azure-cognitive-services/vision/read:3.1-preview
f476d66f5408: Already exists
8882c27f669e: Already exists
d9af21273955: Already exists
f5029279ec12: Already exists
1a578849dcd1: Pull complete
45064b1ab0bf: Download complete
4bb846705268: Downloading [=========================================> ] 187.1MB/222.8MB
c56511552241: Waiting
e91d2aa0f1ad: Downloading [==============================================> ] 162.2MB/176.1MB
下载映像后,映像服务将会启动:
Starting docker_ocr_1 ... done
Starting docker_forms_1 ... doneAttaching to docker_ocr_1, docker_forms_1forms_1 | forms_1 | forms_1 | Notice: This Preview is made available to you on the condition that you agree to the Supplemental Terms of Use for Microsoft Azure Previews [https://go.microsoft.com/fwlink/?linkid=2018815], which supplement your agreement [https://go.microsoft.com/fwlink/?linkid=2018657] governing your use of Azure. If you do not have an existing agreement governing your use of Azure, you agree that your agreement governing use of Azure is the Microsoft Online Subscription Agreement [https://go.microsoft.com/fwlink/?linkid=2018755] (which incorporates the Online Services Terms [https://go.microsoft.com/fwlink/?linkid=2018760]). By using the Preview you agree to these terms.
forms_1 |
forms_1 |
forms_1 | Using '/input' for reading models and other read-only data.
forms_1 | Using '/output/forms/812d811d1bcc' for writing logs and other output data.
forms_1 | Logging to console.
forms_1 | Submitting metering to 'https://westus2.api.cognitive.microsoft.com/'.
forms_1 | WARNING: No access control enabled!
forms_1 | warn: Microsoft.AspNetCore.Server.Kestrel[0]
forms_1 | Overriding address(es) 'http://+:80'. Binding to endpoints defined in UseKestrel() instead.
forms_1 | Hosting environment: Production
forms_1 | Content root path: /app/forms
forms_1 | Now listening on: http://0.0.0.0:5000
forms_1 | Application started. Press Ctrl+C to shut down.
ocr_1 |
ocr_1 |
ocr_1 | Notice: This Preview is made available to you on the condition that you agree to the Supplemental Terms of Use for Microsoft Azure Previews [https://go.microsoft.com/fwlink/?linkid=2018815], which supplement your agreement [https://go.microsoft.com/fwlink/?linkid=2018657] governing your use of Azure. If you do not have an existing agreement governing your use of Azure, you agree that your agreement governing use of Azure is the Microsoft Online Subscription Agreement [https://go.microsoft.com/fwlink/?linkid=2018755] (which incorporates the Online Services Terms [https://go.microsoft.com/fwlink/?linkid=2018760]). By using the Preview you agree to these terms.
ocr_1 |
ocr_1 |
ocr_1 | Logging to console.
ocr_1 | Submitting metering to 'https://westcentralus.api.cognitive.microsoft.com/'.
ocr_1 | WARNING: No access control enabled!
ocr_1 | Hosting environment: Production
ocr_1 | Content root path: /
ocr_1 | Now listening on: http://0.0.0.0:5000
ocr_1 | Application started. Press Ctrl+C to shut down.
验证服务可用性
提示
可以使用 docker images 命令列出下载的容器映像。 例如,以下命令以表格列出每个下载的容器映像的 ID、存储库和标记:
docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"
IMAGE ID REPOSITORY TAG
<image-id> <repository-path/name> <tag-name>
下面是一些示例输出:
IMAGE ID REPOSITORY TAG
2ce533f88e80 mcr.microsoft.com/azure-cognitive-services/form-recognizer/layout-3.1 latest
4be104c126c5 mcr.microsoft.com/azure-cognitive-services/vision/read:3.1-preview latest
测试容器
在主机上打开浏览器,使用 docker-compose.yaml 文件中指定的端口(例如 http://localhost:5021)转到 localhost。 这两个容器的登陆页面都应可用。