快速入門:使用 Azure CLI 在 Azure Container Apps 中建立服務連線
本快速入門說明如何使用 Azure CLI 和服務 連線 or,將 Azure Container Apps 連線到其他雲端資源。 服務 連線 or 可讓您快速將計算服務連線到雲端服務,同時管理連線的驗證和網路設定。
重要
Container Apps 中的服務 連線 or 目前為預覽狀態。 請參閱 Microsoft Azure 預覽版增補使用規定,以了解適用於 Azure 功能 (搶鮮版 (Beta)、預覽版,或尚未正式發行的版本) 的法律條款。
必要條件
Azure 訂用帳戶。 如果您沒有 Azure 訂用帳戶,請在開始之前先建立 Azure 免費帳戶。
至少有一個應用程式部署至 Service 連線 or 所支援區域中的 Container Apps。 如果您沒有容器, 請建立容器並將其部署至 Container Apps。
在 Azure Cloud Shell 中使用 Bash 環境。 如需詳細資訊,請參閱 Azure Cloud Shell 中的 Bash 快速入門。
若要在本地執行 CLI 參考命令,請安裝 Azure CLI。 若您在 Windows 或 macOS 上執行,請考慮在 Docker 容器中執行 Azure CLI。 如需詳細資訊,請參閱〈如何在 Docker 容器中執行 Azure CLI〉。
如果您使用的是本機安裝,請使用 az login 命令,透過 Azure CLI 來登入。 請遵循您終端機上顯示的步驟,完成驗證程序。 如需其他登入選項,請參閱使用 Azure CLI 登入。
出現提示時,請在第一次使用時安裝 Azure CLI 延伸模組。 如需擴充功能詳細資訊,請參閱使用 Azure CLI 擴充功能。
執行 az version 以尋找已安裝的版本和相依程式庫。 若要升級至最新版本,請執行 az upgrade。
必須安裝 2.37.0 版或更新版本的 Azure CLI。 若要升級至最新版本,請執行
az upgrade
。 如果您是使用 Azure Cloud Shell,就已安裝最新版本。Container Apps 擴充功能必須安裝在 Azure CLI 或 Cloud Shell 中。 若要安裝它,請執行
az extension add --name containerapp
。
初始設定
如果您是第一次使用 Service 連線 or,請從執行 az provider register 命令開始註冊 Service 連線 or 資源提供者。
az provider register -n Microsoft.ServiceLinker
提示
您可以執行 命令
az provider show -n "Microsoft.ServiceLinker" --query registrationState
來檢查資源提供者是否已註冊。 如果輸出為Registered
,則服務 連線 或已註冊。或者,執行 az containerapp connection list-support-types 命令,以取得 Container Apps 支援的目標服務清單。
az containerapp connection list-support-types --output table
建立服務連線
使用存取金鑰或受控識別建立連線。
az containerapp connection create
執行 命令,以使用存取密鑰在 Container Apps 與 Azure Blob 儲存體 之間建立服務連線。az containerapp connection create storage-blob --secret
在 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
輸出也會顯示連線的布建狀態:失敗或成功。