Targeting Windows: how do two containers talk to each other on my Dev PC?

Hi,

I am new to docker/container. I created two ASP.NET MVC projects. “MyWebsite” was the web portal and “MyAPI” was the Web API. The web portal invokes the web API to get a string and display it on the web page.

When I launch them from Visual Studio’s docker-compose, both are accessible from my dev PC, one as “http:||localhost:52000” and one as “http:||localhost:52001”. But the web portal could not reach the API.

This is what I have done:

  • I found the host PC’s internal IP address which the container can access, 172.20.64.1, using ipconfig. It was the one against the long GUID.

  • On my host PC’s firewall, I allowed PING. I also allowed all incoming and outgoing connections at port 1024-65535.

After that, I can ping from the MyWebsite container this host IP address:

`docker exec -it MyWebsite ping 172.26.176.1`

But, when MyWebsite tries to invoke MyAPI by this IP address, which is

http:||172.20.64.1:52001/api/values/5

It can’t reach it.

What can I do? Please help. Thanks.

I worked out. All I need to do is to invoke the API by its container name:

http://myapi/api/values/5

Dns-based service discovery is only available for user defined networks. It is not available for containers attached to the default bridge (when no --network is specified in docker run). Docker compose deployments always create and use a user defined bridge.

Further details can be found here:
https://docs.docker.com/network/bridge/#differences-between-user-defined-bridges-and-the-default-bridge