Bagikan melalui


Menggunakan Docker Compose untuk menyebarkan beberapa kontainer Azure AI

Artikel ini memperlihatkan kepada Anda cara menyebarkan beberapa kontainer Azure AI. Secara khusus, Anda akan mempelajari cara menggunakan Docker Compose untuk mengatur beberapa gambar kontainer Docker pada satu komputer host. Contoh dalam artikel ini adalah menyebarkan kontainer Kecerdasan Dokumen dan kontainer Visi AI baca bersama-sama.

Catatan

Docker Compose adalah alat untuk mendefinisikan dan menjalankan aplikasi Docker multi-kontainer. Di Compose, Anda menggunakan file YAML untuk mengonfigurasi layanan aplikasi Anda. Kemudian, Anda membuat dan memulai semua layanan dari konfigurasi dengan menjalankan satu perintah.

Prasyarat

Prosedur ini memerlukan beberapa alat yang harus diinstal dan dijalankan secara lokal:

  • Langganan Azure. Jika Anda tidak memilikinya, buat akun gratis sebelum memulai.
  • Docker Engine. Pastikan bahwa Docker CLI berfungsi di jendela konsol.
  • Sumber daya Azure dengan tingkat harga yang benar. Hanya tingkat harga berikut yang berfungsi dengan kontainer ini:
    • Sumber daya Azure AI Vision hanya dengan tingkat harga F0 atau Standar.
    • Kecerdasan Dokumen sumber daya dengan tingkat harga F0 atau Standar saja.
    • Sumber daya layanan Azure AI dengan tingkat harga S0.
  • Jika Anda menggunakan kontainer pratinjau yang terjaga, Anda harus mengisi formulir permintaan online untuk menggunakannya.

File Docker Compose

File YAML menentukan semua kontainer layanan Azure AI yang akan disebarkan. Layanan ini mengandalkan DockerFile atau gambar kontainer yang ada. Dalam hal ini, kita akan menggunakan dua gambar. Salin dan tempel file YAML berikut, dan simpan sebagai docker-compose.yaml. Berikan nilai apikey, billing, dan EndpointUri yang sesuai dalam file.

Penting

Pastikan untuk membuat direktori pada komputer host yang ditentukan di bawah simpul volumes , atau berikan direktori yang ada di komputer Anda. Direktori ini harus ada sebelum Anda mencoba memasang gambar dengan menggunakan pengikatan volume.

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 Azure AI Vision API key >
      billing: # < Your Azure AI Vision billing URL >
    ports:
      - "5021:5000"

Memulai layanan Docker Compose yang dikonfigurasi

File Docker Compose memungkinkan manajemen semua tahapan dalam siklus hidup layanan yang ditentukan: memulai, menghentikan, dan membuat kembali layanan; melihat status layanan; dan streaming log. Buka antarmuka baris perintah dari direktori proyek (tempat file docker-compose.yaml berada).

Dari antarmuka baris perintah, jalankan perintah berikut untuk memulai (atau memulai ulang) semua layanan yang ditentukan dalam file docker-compose.yaml:

docker-compose up

Pertama kali Docker menjalankan perintah docker-compose up dengan menggunakan konfigurasi ini, Docker menarik gambar yang dikonfigurasi di bawah simpul layanan dan kemudian mengunduh dan memasangnya:

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

Setelah gambar diunduh, layanan gambar dimulai:

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.

Memverifikasi ketersediaan layanan

Tips

Anda dapat menggunakan perintah gambar docker untuk mencantumkan gambar kontainer yang diunduh. Misalnya, perintah berikut mencantumkan ID, repositori, dan tag dari setiap gambar kontainer yang diunduh, yang diformat sebagai tabel:

docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"

IMAGE ID         REPOSITORY                TAG
<image-id>       <repository-path/name>    <tag-name>

Berikut adalah beberapa contoh output:

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

Menguji kontainer

Buka browser di komputer host dan buka localhost dengan menggunakan port yang ditentukan dari file docker-compose.yaml, seperti http://localhost:5021. Kedua halaman arahan kontainer harus tersedia.

Cuplikan layar halaman utama kontainer.

Langkah berikutnya

Kontainer Azure AI