How host.docker.internal works on Windows?

I just want to understand why on Windows the IP of host.docker.internal is not the IP of the host, neither

How all of this works on Docker?

I’ve already read the documentation but couldn’t understand how this all works out.


  1. The connection flows like that: container > > host.docker.internal > host ?

  2. If yes, why it doesn’t connects directly to the host instead of going through host.docker.internal?

  3. Why on linux you can set the host.docker.internal as

  4. Why if you set the destination of a package on a container to it doesn’t go to the host?

It is never the IP of the host. I wrote about that here:

Host.docker.internal in production environment - #4 by rimelek

Since that domain is to forward a request to the localhost of your host, it could not be the ip of he host. Docker Desktop for Linux probably works the same way, but you can override the domain on any platform using --add-host or extra_hosts in compose.

Because you are in a virtual machine and the docker network gateways on docker bridge networks are the IP addresses of the docker host which is the virtual machine, not the physical host.