【问题标题】:Azurite Access local blobs on emulatorAzurite 访问模拟器上的本地 blob
【发布时间】:2022-10-20 16:14:49
【问题描述】:

上下文:我正在构建一个 Web 应用程序,它从 json 文件中读取数据,我的计划是将这些 json 平面文件托管在 Azure blob 存储中,然后通过 API 将它们公开给我的 Web 应用程序。现在,我正在尝试构建一个本地开发环境。

我的短期目标是在 docker 容器中设置 azurite 并构建一个简单的控制台应用程序,该应用程序连接到本地 azurite 模拟器并读取一个 json 文件。

首先,我使用 docker compose 文件在 docker 容器中运行 azurite。

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
 

这似乎工作得很好,请注意 https:

我使用mkcert 创建了证书

但是,如果我运行以下

    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);
        }
    }

我得到以下异常:

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

我的直觉告诉我,dotnet 应用程序需要以某种方式使用证书来访问在 docker 上运行的 azurite,但是在这方面我太菜鸟了,有没有人知道我哪里出错了?

【问题讨论】:

    标签: docker-compose azurite


    【解决方案1】:

    这是直截了当的解决方案,您所要做的就是允许远程连接到您的 docker compose 文件中的 azurite。

    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
    

    注意 --blobhost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0

    它在 MSDN 上提到,在“允许远程请求”上执行 ctr+f https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?tabs=docker-hub

    还要确保您阅读了“证书配置 (HTTPS)”部分 并通过 https 连接字符串连接到模拟器。

    【讨论】:

      猜你喜欢
      • 2020-05-23
      • 1970-01-01
      • 1970-01-01
      • 2020-02-04
      • 2016-07-09
      • 2012-10-20
      • 1970-01-01
      • 2013-04-08
      • 1970-01-01
      相关资源
      最近更新 更多