I'm using a Windows machine with Docker Desktop installed. My project does not live inside a docker container.
But as evident to https://youtrack.jetbrains.com/issue/IDEA-263484, it seems that Docker Desktop has overridden my host file to function properly, and the following code now returns an incorrect hostname.
InetAddress.getLocalhost().getCanonicalHostname() // host.docker.internal
This is my host file
#...
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
# Added by Docker Desktop
192.168.128.75 host.docker.internal
192.168.128.75 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
Is there another standard method (that is cross-platform) to detect real machine hostname that works with Docker Desktop installations?
As mentioned in the linked issue and in Rob's answer, I could probably add an entry in my host file to mitigate this issue, but this might not work too well if the IP gets changed, and requires additional setup.