Sdílet prostřednictvím


Použití nástroje Docker Compose k nasazení několika kontejnerů

V tomto článku se dozvíte, jak nasadit více kontejnerů Azure AI. Konkrétně se dozvíte, jak pomocí Docker Compose orchestrovat několik imagí kontejneru Dockeru.

Docker Compose je nástroj pro definování a spouštění aplikací Dockeru s více kontejnery. V aplikaci Compose použijete soubor YAML ke konfiguraci služeb vaší aplikace. Pak vytvoříte a spustíte všechny služby z vaší konfigurace spuštěním jednoho příkazu.

Může být užitečné orchestrovat více imagí kontejnerů na jednom hostitelském počítači. V tomto článku vytvoříme kontejnery Read and Document Intelligence.

Požadavky

Tento postup vyžaduje několik nástrojů, které je potřeba nainstalovat a spustit místně:

  • Předplatné Azure. Pokud ho nemáte, vytvořte si bezplatný účet před tím, než začnete.
  • Docker Engine. Ověřte, že rozhraní příkazového řádku Dockeru funguje v okně konzoly.
  • Prostředek Azure se správnou cenovou úrovní S tímto kontejnerem fungují pouze následující cenové úrovně:
    • Prostředek Azure AI Vision s cenovou úrovní F0 nebo Standard
    • Prostředek Document Intelligence s cenovou úrovní F0 nebo Standard
    • Prostředek služeb Azure AI s cenovou úrovní S0
  • Pokud používáte vrátný kontejner ve verzi Preview, budete muset vyplnit online formulář žádosti, aby ho bylo možné použít.

Soubor Docker Compose

Soubor YAML definuje všechny služby, které se mají nasadit. Tyto služby spoléhají na image DockerFile kontejneru nebo na existující image kontejneru. V tomto případě použijeme dva náhledové obrázky. Zkopírujte a vložte následující soubor YAML a uložte ho jako docker-compose.yaml. Zadejte v souboru příslušné hodnoty apikey, fakturace a 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"

Důležité

Na hostitelském počítači, který je zadaný pod uzlem svazků , vytvořte adresáře. Tento přístup je povinný, protože adresáře musí existovat před pokusem o připojení image pomocí vazeb svazků.

Spuštění nakonfigurovaných služeb Docker Compose

Soubor Docker Compose umožňuje správu všech fází v životním cyklu definované služby: spuštění, zastavení a opětovné sestavení služeb; zobrazení stavu služby; a streamování protokolů. Otevřete rozhraní příkazového řádku z adresáře projektu (kde se nachází soubor docker-compose.yaml).

Poznámka:

Abyste se vyhnuli chybám, ujistěte se, že hostitelský počítač správně sdílí jednotky s Modulem Dockeru. Pokud se například E:\publicpreview používá jako adresář v souboru docker-compose.yaml , nasdílejte jednotku E s Dockerem.

Z rozhraní příkazového řádku spusťte následující příkaz, který spustí (nebo restartuje) všechny služby definované v souboru docker-compose.yaml :

docker-compose up

Při prvním spuštění příkazu docker-compose up pomocí této konfigurace načte image nakonfigurované v uzlu služeb a pak je stáhne a připojí:

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

Po stažení imagí se spustí služby imagí:

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.

Ověření dostupnosti služby

Tip

K výpisu stažených imagí kontejnerů můžete použít příkaz docker images . Následující příkaz například vypíše ID, úložiště a značku každé stažené image kontejneru, která je formátovaná jako tabulka:

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

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

Tady je příklad výstupu:

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

Testování kontejnerů

Otevřete prohlížeč na hostitelském počítači a přejděte na localhost pomocí zadaného portu ze souboru docker-compose.yaml , například . http://localhost:5021/swagger/index.html. K otestování koncového bodu Document Intelligence můžete například použít funkci Vyzkoušet v rozhraní API. Obě stránky swaggeru kontejnerů by měly být dostupné a testovatelné.

Kontejner analýzy dokumentů

Další kroky

Kontejnery Azure AI