Monday, 25 October 2021

Unable to ping host.docker.internal

 This is the problem people out there facing a lot where their docker containers are unable to connect to docker host.

In general, host IP will be changing specially in dev machine and this create trouble for docker to resolve the host DNS and establish the connection. Hence Docker recommend a special DNS name host.docker.internal to use which resolves to the internal IP address used by the host.

In windows, we need to add below entry to the C:\Windows\System32\drivers\etc\hosts file as:
192.XXX.XX.XX host.docker.internal

All good but there is a problem where docker containers are unable to ping host.docker.internal and I too face the problem every time I restart the system. There is a huge discussion here and the channel is closed and I don’t see a working solution.

After struggling a lot, finally I figured out a working solution for me which I’m using it since last one month from the date I’m writing this post. Solution is, run the below command once when you restart your system, basically it is a cleanup command to clean unused resources like unused network, cache, unused & dangling containers. Read here more about this.

docker system prune

My Environment:
OS: Windows 10 Enterprise
Docker Desktop Version: 4.1.1

Hope this helps you. Thank you for reading.

No comments:

Post a Comment