Share via


快速入門:使用 Azure CLI 在 Azure Container Apps 中建立服務連線

本快速入門說明如何使用 Azure CLI 和服務 連線 or,將 Azure Container Apps 連線到其他雲端資源。 服務 連線 or 可讓您快速將計算服務連線到雲端服務,同時管理連線的驗證和網路設定。

重要

Container Apps 中的服務 連線 or 目前為預覽狀態。 請參閱 Microsoft Azure 預覽版增補使用規定,以了解適用於 Azure 功能 (搶鮮版 (Beta)、預覽版,或尚未正式發行的版本) 的法律條款。

必要條件

  • 必須安裝 2.37.0 版或更新版本的 Azure CLI。 若要升級至最新版本,請執行 az upgrade。 如果您是使用 Azure Cloud Shell,就已安裝最新版本。

  • Container Apps 擴充功能必須安裝在 Azure CLI 或 Cloud Shell 中。 若要安裝它,請執行 az extension add --name containerapp

初始設定

  1. 如果您是第一次使用 Service 連線 or,請從執行 az provider register 命令開始註冊 Service 連線 or 資源提供者。

    az provider register -n Microsoft.ServiceLinker
    

    提示

    您可以執行 命令 az provider show -n "Microsoft.ServiceLinker" --query registrationState來檢查資源提供者是否已註冊。 如果輸出為 Registered,則服務 連線 或已註冊。

  2. 或者,執行 az containerapp connection list-support-types 命令,以取得 Container Apps 支援的目標服務清單。

    az containerapp connection list-support-types --output table
    

建立服務連線

使用存取金鑰或受控識別建立連線。

  1. az containerapp connection create執行 命令,以使用存取密鑰在 Container Apps 與 Azure Blob 儲存體 之間建立服務連線。

    az containerapp connection create storage-blob --secret
    
  2. 在 Azure CLI 的要求中提供下列資訊:

    設定 描述
    The resource group that contains the container app 具有容器應用程式的資源群組名稱。
    Name of the container app 容器應用程式的名稱。
    The container where the connection information will be saved 容器應用程式容器的名稱。
    The resource group which contains the storage account 具有記憶體帳戶的資源群組名稱。
    Name of the storage account 您想要連線的記憶體帳戶名稱。 在本指南中,我們使用 Blob 儲存體。

提示

如果您沒有 Blob 儲存體,您可以執行 az containerapp connection create storage-blob --new --secret 來布建新的 Blob 儲存體,並使用 連接字串 直接連線到您的容器應用程式。

檢視連線

使用 Azure CLI 命令 az containerapp connection list 來列出您所有容器應用程式的布建連線。 以容器應用程式的資源群組名稱與名稱取代下列命令的佔位元<container-app-resource-group><container-app-name>和 。 您也可以移除 --output table 選項,以檢視連線的詳細資訊。

az containerapp connection list -g "<container-app-resource-group>" --name "<container-app-name>" --output table

輸出也會顯示連線的布建狀態:失敗或成功。

下一步