I have a .NET 6 API (running in Docker), and Azurite (running in Docker).
I’m trying to connect to Azurite from the .NET app using the .NET SDK, but am getting the following error in the Docker logs:
System.AggregateException: Retry failed after 6 tries. Retry settings
can be adjusted in ClientOptions.Retry. (Connection refused
(azurite:10000)) (Connection refused (azurite:10000)) (Connection
refused (azurite:10000)) (Connection refused (azurite:10000))
(Connection refused (azurite:10000)) (Connection refused
(azurite:10000))
It’s dying on this second line (CreateIfNotExists()
):
_blobContainerClient = new BlobContainerClient(connectionString, containerName);
_blobContainerClient.CreateIfNotExists();
Here’s my connection string in my .NET app:
"Azure": {
"StorageConnectionString": "UseDevelopmentStorage=true"
}
Here is my docker-compose.yml
file:
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
Things to note:
- I’m overriding the connection string in the compose file, by using the
environment
variable - I’ve set the
DevelopmentStorageProxyUri
to the hostname (azurite) - I’m using
depends_on
to ensure that Azurite starts up before the API
I noticed this similar question, however it seems outdated and doesn’t’ have a clear answer.
Can anyone help?
Thanks in advance.
2
Answers
Got it working with the help of @peinearydevelopment's answer.
I had to change my
docker-compose
file to:The main thing was using the proper Azure Connection String, and making sure the ports matched up to what was being set in the azurite command.
I had a hard time with this as well. At the end of the day, this is how I got it working:
docker-compose.yaml
Connection string used in the app:
DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://host.docker.internal:10010/devstoreaccount1;QueueEndpoint=http://host.docker.internal:10011/devstoreaccount1;
I’m passing in the connection string with and env file, but it should work just as well in your
local.settings.json
file.