NAT constantly breaking stopping containers talking to each other, and host -> container access

Hi all,

I’m having a major headache with Docker at the moment. Windows containers randomly stop being able to resolve each other by ID or name (they can communicate via their IPs), and I randomly stop being able to access their exposed ports on the host. I’m pretty sure it’s a NAT issue. I’m currently running the edge release (19.03.0-rc2) of Docker, and Windows 10 1903.

Sometimes rebooting docker fixes it, sometimes rebooting my laptop fixes it, sometimes the only fix seems to be stopping the service and manually deleting all the folders in C:\programdata\Docker\containers.

Sleeping/waking the laptop seems to often trip this problem from what I can tell.

For example, if I create an ASP.NET container running IIS:

docker run --name aspnet1 -p 8001:80 mcr.microsoft.com/dotnet/framework/aspnet

I can’t talk to it:

telnet localhost 8001
Connecting To localhost...Could not open connection to the host, on port 8001: Connect failed

If I inspect the container I can see its NAT IP is 172.21.60.104, which is from the Hyper-V “nat” adapter, I can’t ping this or telnet to it either. When everything’s working I am able to ping/telnet to it.

If I run ipconfig on the container to get its internal IP (docker exec -it aspnet1 ipconfig) I can see it’s 192.168.181.198, which is from the Hyper-V “default switch” adapter. Pinging/telnetting to this IP (on port 80) works fine still.

Running Linux based containers whilst in “Windows containers” mode seems to always work, I can access http://localhost:8000 here:

docker run --name nginx1 -p 8000:80 nginx

And I can do container -> container communication too:

docker run -it --rm bash ping nginx1
PING nginx1 (172.21.61.237): 56 data bytes
64 bytes from 172.21.61.237: seq=0 ttl=64 time=0.921 ms

Can anyone help?

It’s causing me major amounts of wasted time at the moment. I can’t see anything of relevance in any of the logs I’ve looked at, but I’m also not entirely sure if I’m looking in the right place so any suggestions would be great.


Thanks

Oh and as a bonus, here’s a Wireshark trace when I try and access the ASP.NET container from my phone on my local network (my phone’s IP is 192.168.0.4, my laptop is 192.168.0.5).

I’m not an expert on this sort of thing, but it looks like something is definitely trying to forward this port over to the NAT adapter’s address but failing:

I just came across Docker for Windows use Hyper-V vEthernet (Default Switch) by default which states that the result of running ipconfig on the container, and docker inspect, should show the same IP which my posts above show weren’t the case for me.

As suggested I just ran docker network prune and started a new container and it appears to allow me to connect to it again.

I wonder if this was the problem all along? Hopefully someone comes across this post and it helps them out. The caveat seems to be you might have to run this command every time Docker restarts.