简体   繁体   English

无法从同一台计算机上的Docker容器连接到Azure存储模拟器

[英]Unable to connect to Azure Storage Emulator from a docker container on the same machine

I dockerized a .net core 2.2 web api application in Visual Studio 2017 successfully. 我在Visual Studio 2017中成功地对.net core 2.2 Web API应用程序进行了docker化。 One part of this application is supposed to store some data to Azure Storage Emulator running on the same machine as VS 2017 is running on. 该应用程序的一部分应该将一些数据存储到与VS 2017运行所在同一台计算机上运行的Azure存储模拟器。 The emulator's configuration looks like below: 仿真器的配置如下所示:

<services>
   <service name="Blob" url="http://127.0.0.1:10000/"/>
   <service name="Queue" url="http://127.0.0.1:10001/"/>
   <service name="Table" url="http://127.0.0.1:10002/"/>
</services>

docker-compose.yml file has the following network definition: docker-compose.yml文件具有以下网络定义:

build:
      context: .
      dockerfile: MyWebApi\Dockerfile
      network: host

I am able to view the web api's output at https://127.0.0.1:44315/api/values 我可以在https://127.0.0.1:44315/api/values查看Web api的输出

Per my understanding, "host" network configuration did its job by assigning the container's host's IP address to the container which seems good so far. 根据我的理解,“主机”网络配置通过将容器的主机IP地址分配给容器来完成其工作,到目前为止,这似乎还不错。 The question is that why the dockerized web app in the container fails to communicate with the emulator in spite of the mentioned configuration. 问题是,尽管有上述配置,为什么容器中的dockerized Web应用仍无法与仿真器通信。 What is missing in this exercise? 此练习中缺少什么?

As far as I remember, the Azure Storage Emulator is bound in a local-only network configuration and Docker for Windows runs in a VM using Hyper-V . 据我所知, Azure存储模拟器绑定在仅限本地的网络配置中, 适用于Windows的Docker在使用Hyper-VVM中运行。

I'm afraid the solution would be to use the microsoft/azure-storage-emulator image while developing and point your API to it. 恐怕解决方案是在开发时使用microsoft / azure-storage-emulator映像并将您的API指向它。

Update 更新资料

You could also try and use host.docker.internal instead of 127.0.0.1 as the host in the connection string (this also might let you use the emulator running on your host instead of the container). 您也可以尝试使用host.docker.internal而不是127.0.0.1作为连接字符串中的主机(这也可以让您使用在主机上而不是容器上运行的仿真器)。

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM