0

Context: I'm building a web app, that reads data from json files, my plan is to host these json flatfiles in Azure blob storage, then to expose them to my Web app through an API. Right now, I am trying to build a local dev environment.

My short-term goal is to setup azurite in a docker container and build a simple console app that connect to the local azurite emulator and reads one json file.

to get started, I have the azurite running in a docker container using a docker compose file.

version: '3.9'
services:
  azurite:
    image: mcr.microsoft.com/azure-storage/azurite
    container_name: 'azurite-console'
    hostname: azurite
    restart: always
    command: 'azurite --oauth basic --cert /workspace/127.0.0.1.pem --key /workspace/127.0.0.1-key.pem'
    ports:
      - 10000:10000
      - 10001:10001
      - 10002:10002  
    volumes:
      - ./certs:/workspace
 

This seems to be working just fine, notice the https:

enter image description here

I created the certificates using mkcert

however, if I run the following

    static void Main(string[] args)
    {
        // With container URL and DefaultAzureCredential
        var client = new BlobServiceClient(
            new Uri("https://127.0.0.1:10000"),
            new DefaultAzureCredential()
        );
        Console.WriteLine("\nlist containers");
        try
        {
            var containers = client.GetBlobContainers();
            foreach (var c in containers)
                Console.WriteLine(c.Name);
        }
        catch(Exception ex){
            Console.WriteLine(ex.Message);
        }
    }

I get the following exception:

Retry failed after 6 tries. Retry settings can be adjusted in ClientOptions.Retry. (The SSL connection could not be established, see inner exception.)

my gut tells me that the dotnet app somehow needs to use the certificate to access azurite running on docker, but I'm too much of a noob when it comes to this, does anyone have any ideas of where i am going wrong?

Paweł Ciucias
  • 108
  • 1
  • 8

1 Answers1

0

it was straight forward solution all you have to do is allow remote connection to azurite in you docker compose file.

version: '3.9'
services:
  azurite:
    image: mcr.microsoft.com/azure-storage/azurite
    container_name: "azurite-PAG"
    hostname: azurite
    restart: always
    command: 'azurite --oauth basic --cert /workspace/127.0.0.1.pem --key /workspace/127.0.0.1-key.pem --location /workspace --debug /workspace/debug.log --blobHost 0.0.0.0  --queueHost 0.0.0.0 --tableHost 0.0.0.0  --loose'
    ports:
      - "10000:10000"
      - "10001:10001"
      - "10002:10002" 
    volumes:
      - ./azuriteData:/workspace

Notice the --blobhost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0

it's mentioned on MSDN, do a ctr+f on "Allow remote requests" https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?tabs=docker-hub

also make sure that you read the section on "Certificate configuration (HTTPS)" and connecting to the emulator via the https connection string.

Paweł Ciucias
  • 108
  • 1
  • 8