我有一個 .NET 6 API(在 Docker 中運行)和 Azurite(在 Docker 中運行)。
我正在嘗試使用 .NET SDK 從 .NET 應用程式連接到 Azurite,但在 Docker 日志中出現以下錯誤:
System.AggregateException:6 次嘗試后重試失敗。可以在 ClientOptions.Retry 中調整重試設定。(連接被拒絕 (azurite:10000)) (連接被拒絕 (azurite:10000)) (連接被拒絕 (azurite:10000)) (連接被拒絕 (azurite:10000)) (連接被拒絕 (azurite:10000)) (連接被拒絕 (azurite :10000))
它在第二行(CreateIfNotExists())上死了:
_blobContainerClient = new BlobContainerClient(connectionString, containerName);
_blobContainerClient.CreateIfNotExists();
這是我的 .NET 應用程式中的連接字串:
"Azure": {
"StorageConnectionString": "UseDevelopmentStorage=true"
}
這是我的docker-compose.yml檔案:
version: '3.4'
services:
api:
image: ${DOCKER_REGISTRY-}api
container_name: aft-backend-api
build:
context: src
dockerfile: API/Dockerfile
networks:
- aft-backend
environment:
- ASPNETCORE_URLS=http:// :5000
- Azure__StorageConnectionString=UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://azurite;
depends_on:
- azurite
azurite:
image: mcr.microsoft.com/azure-storage/azurite
container_name: aft-backend-azurite
hostname: azurite
restart: always
command: 'azurite --blobHost 127.0.0.1 --blobPort 10000 --queueHost 127.0.0.1 --queuePort 10001'
ports:
- 10000:10000
- 10001:10001
networks:
- aft-backend
networks:
aft-backend:
name: aft-backend-network
注意事項:
- 我正在使用
environment變數覆寫撰寫檔案中的連接字串 - 我已將 設定
DevelopmentStorageProxyUri為主機名(藍銅礦) - 我
depends_on用來確保 Azurite 在 API 之前啟動
我注意到這個類似的問題,但是它似乎已經過時并且沒有明確的答案。
任何人都可以幫忙嗎?
提前致謝。
uj5u.com熱心網友回復:
我也遇到了困難。歸根結底,這就是我的作業方式:
docker-compose.yaml
version: "3.9"
services:
azurite:
image: mcr.microsoft.com/azure-storage/azurite
command: "azurite --loose --blobHost 0.0.0.0 --blobPort 10000 --queueHost 0.0.0.0 --queuePort 10001 --location /workspace --debug /workspace/debug.log"
ports:
- 10010:10000
- 10011:10001
- 10012:10002
volumes:
- ./azurite:/workspace
backend:
build:
context: backend
args:
AzureWebJobsStorage: "${AzureWebJobsStorage}"
ports:
- 10004:80
depends_on:
- azurite
應用程式中使用的連接字串:DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://host.docker.internal:10010/devstoreaccount1;QueueEndpoint=http://host.docker.internal:10011/devstoreaccount1;
我將連接字串與 env 檔案一起傳遞,但它應該在您的local.settings.json檔案中也能正常作業。
uj5u.com熱心網友回復:
在@peinearydevelopment 的回答的幫助下讓它作業。
我不得不將我的docker-compose檔案更改為:
version: '3.4'
services:
api:
image: ${DOCKER_REGISTRY-}api
container_name: aft-backend-api
build:
context: src
dockerfile: API/Dockerfile
networks:
- aft-backend
environment:
- ASPNETCORE_URLS=http:// :5000
- Azure__StorageConnectionString=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://host.docker.internal:10000/devstoreaccount1;QueueEndpoint=http://host.docker.internal:10001/devstoreaccount1;
depends_on:
- azurite
azurite:
image: mcr.microsoft.com/azure-storage/azurite
container_name: aft-backend-azurite
hostname: azurite
restart: always
command: 'azurite --loose --blobHost 0.0.0.0 --blobPort 10000 --queueHost 0.0.0.0 --queuePort 10001 --location /workspace --debug /workspace/debug.log'
ports:
- 10000:10000
- 10001:10001
volumes:
- ./azurite:/workspace
networks:
- aft-backend
networks:
aft-backend:
name: aft-backend-network
主要是使用正確的 Azure 連接字串,并確保埠與 azurite 命令中設定的埠匹配。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/420877.html
標籤:
