استخدام Docker Compose لنشر حاويات متعددة

توضح لك هذه المقالة كيفية نشر حاويات خدمات Azure الذكاء الاصطناعي متعددة. على وجه التحديد، ستتعلم كيفية استخدام Docker Compose لتنسيق صور حاوية Docker متعددة.

Docker Compose هو أداة لتعريف وتشغيل تطبيقات Docker متعددة الحاويات. في إنشاء، يمكنك استخدام ملف YAML لتكوين خدمات التطبيق الخاص بك. بعد ذلك، يمكنك إنشاء جميع الخدمات وبدء تشغيلها من التكوين الخاص بك عن طريق تشغيل أمر واحد.

يمكن أن يكون من المفيد تنسيق صور حاوية متعددة على كمبيوتر مضيف واحد. في هذه المقالة، سنجمع حاويات قراءة وذكاء المستند معا.

المتطلبات الأساسية

يتطلب هذا الإجراء تثبيت العديد من الأدوات وتشغيلها محليًا:

  • اشتراك Azure. في حال لم يكن لديك اشتراك Azure، أنشئ حسابًا مجّانيًّا قبل البدء.
  • محرك Docker. تأكد من أن Docker CLI يعمل في نافذة وحدة التحكم.
  • مورد Azure بمستوى تسعير صحيح. تعمل مستويات التسعير التالية فقط مع هذه الحاوية:
    • مورد Azure الذكاء الاصطناعي Vision مع مستوى تسعير F0 أو Standard فقط.
    • مورد ذكاء المستند مع مستوى التسعير F0 أو Standard فقط.
    • مورد خدمات Azure الذكاء الاصطناعي مع مستوى تسعير S0.
  • إذا كنت تستخدم حاوية معاينة مسورة، فستحتاج إلى إكمال نموذج الطلب عبر الإنترنت لاستخدامه.

ملف Docker Compose

يعرف ملف YAML جميع الخدمات التي سيتم نشرها. تعتمد هذه الخدمات على DockerFile أو صورة حاوية موجودة. في هذه الحالة، سنستخدم صورتي معاينة. نسخ ولصق الملف YAML التالية، وحفظه بصيغة docker-compose.yaml. قم بتوفير قيم apikeyوالفوترةوEndpointUri المناسبة في الملف.

version: '3.7'
services:
  forms:
    image: "mcr.microsoft.com/azure-cognitive-services/form-recognizer/layout"
    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:\publicpreview\output
         target: /output
       - type: bind
         source: E:\publicpreview\input
         target: /input
    ports:
      - "5010:5000"

  ocr:
    image: "mcr.microsoft.com/azure-cognitive-services/vision/read:3.1-preview"
    environment:
      eula: accept
      apikey: # < Your Azure AI Vision API key >
      billing: # < Your Azure AI Vision billing URL >
    ports:
      - "5021:5000"

هام

إنشاء الدلائل على الجهاز المضيف التي تم تحديدها ضمن عقدة وحدات التخزين. هذا الأسلوب مطلوب لأن الدلائل يجب أن تكون موجودة قبل محاولة تحميل صورة باستخدام روابط وحدة التخزين.

بدء تشغيل خدمات Docker Compose المكونة

يتيح ملف Docker Compose إدارة جميع المراحل في دورة حياة خدمة محددة: بدء الخدمات وإيقافها وإعادة إنشائها؛ عرض حالة الخدمة؛ وسجل البث. افتح واجهة سطر الأوامر من دليل المشروع (حيث يوجد ملف docker-compose.yaml).

ملاحظة

لتجنب الأخطاء، تأكد من أن الجهاز المضيف يشارك محركات الأقراص بشكل صحيح مع Docker Engine. على سبيل المثال، إذا تم استخدام E:\publicpreview كدليل في ملف docker-compose.yaml، فشارك محرك الأقراص E مع Docker.

من واجهة سطر الأوامر، قم بتنفيذ الأمر التالي لبدء (أو إعادة تشغيل) جميع الخدمات المعرفة في ملف docker-compose.yaml:

docker-compose up

في المرة الأولى التي ينفذ فيها Docker الأمر docker-compose up باستخدام هذا التكوين، فإنه يسحب الصور التي تم تكوينها ضمن عقدة الخدمات ثم يقوم بتنزيلها وتحميلها:

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 لسرد صور الحاوية التي تم تنزيلها. على سبيل المثال، يسرد الأمر التالي المعرّف والمستودع والعلامة الخاصة بكل صورة حاوية تم تنزيلها، منسقة في شكل جدول:

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          latest
4be104c126c5        mcr.microsoft.com/azure-cognitive-services/vision/read:3.1-preview         latest

اختبار الحاويات

افتح مستعرضا على الجهاز المضيف وانتقل إلى localhost باستخدام المنفذ المحدد من ملف docker-compose.yaml، مثل http://localhost:5021/swagger/index.html. على سبيل المثال، يمكنك استخدام ميزة Try It في واجهة برمجة التطبيقات لاختبار نقطة نهاية Document Intelligence. يجب أن تكون صفحات swagger للحاويتين متاحة وقابلة للاختبار.

حاوية معلومات المستند

الخطوات التالية

حاويات خدمات Azure الذكاء الاصطناعي