简体   繁体   中英

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. 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. 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:

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

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. The question is that why the dockerized web app in the container fails to communicate with the emulator in spite of the mentioned configuration. 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 .

I'm afraid the solution would be to use the microsoft/azure-storage-emulator image while developing and point your API to it.

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).

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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