RPM*_*984 2 .net docker docker-compose azurite
我有一个 .NET 6 API(在 Docker 中运行)和 Azurite(在 Docker 中运行)。
我尝试使用 .NET SDK 从 .NET 应用程序连接到 Azurite,但在 Docker 日志中收到以下错误:
System.AggregateException: 6 次尝试后重试失败。可以在 ClientOptions.Retry 中调整重试设置。(连接被拒绝(蓝铜矿:10000))(连接被拒绝(蓝铜矿:10000))(连接被拒绝(蓝铜矿:10000))(连接被拒绝(蓝铜矿:10000))(连接被拒绝(蓝铜矿:10000))(连接被拒绝(蓝铜矿:10000))(连接被拒绝(蓝铜矿:10000)) :10000))
它在第二行 ( CreateIfNotExists()
) 处即将消失:
_blobContainerClient = new BlobContainerClient(connectionString, containerName);
_blobContainerClient.CreateIfNotExists();
Run Code Online (Sandbox Code Playgroud)
这是我的 .NET 应用程序中的连接字符串:
"Azure": {
"StorageConnectionString": "UseDevelopmentStorage=true"
}
Run Code Online (Sandbox Code Playgroud)
这是我的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
Run Code Online (Sandbox Code Playgroud)
注意事项:
environment
我通过使用变量覆盖撰写文件中的连接字符串DevelopmentStorageProxyUri
为主机名(azurite)depends_on
确保 Azurite 在 API 之前启动我注意到这个类似的问题,但它似乎已经过时并且没有明确的答案。
有人可以帮忙吗?
提前致谢。
我对此也感到很难过。归根结底,这就是我让它工作的方式:
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
Run Code Online (Sandbox Code Playgroud)
应用程序中使用的连接字符串:DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://host.docker.internal:10010/devstoreaccount1;QueueEndpoint=http://host.docker.internal:10011/devstoreaccount1;
local.settings.json
我正在使用 env 文件传递连接字符串,但它在您的文件中应该同样有效。
在@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
Run Code Online (Sandbox Code Playgroud)
最主要的是使用正确的 Azure 连接字符串,并确保端口与 azurite 命令中设置的端口匹配。
归档时间: |
|
查看次数: |
6802 次 |
最近记录: |