Skip to content

Cannot Connect to Localhost

This one is more of a bug TIL that has been annoying me lately.

Somewhat recently IntelliJ started to fail connecting to localhost when syncing an maven based project.

Caused by: java.rmi.ConnectException: Connection refused to host:; nested exception is: Connection refused (Connection refused)
 at java.rmi/sun.rmi.transport.tcp.TCPEndpoint.newSocket(
 at java.rmi/sun.rmi.transport.tcp.TCPChannel.createConnection(
 at java.rmi/sun.rmi.transport.tcp.TCPChannel.newConnection(

During troubleshooting, the caches were invalidated/restarted and the .idea directory was wiped and re-built but to no avail.

Found an article that was the exact problem.

Turns out, docker-for-desktop was adding a localhost line to the /etc/hosts file and for whatever reason DNS in intellij did not like that.

# Host Database
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##       localhost broadcasthost
::1             localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container: kubernetes.docker.internal
# End of section

Removing the lines for docker-for-desktop fixed the issue.