'spring boot cloud eurka windows 10 eurkea returns host.docker.internal for client host name after latest docker upgrade

Spring Boot Cloud Disovery Question, Problem with Eureka hostname after docker upgrade on windows 10. (Note: docker is not hosting spring services, just mariadb, rabbitmq, and zipkin)

Summary

  • I am developing on windows 10 enterpise, latest patch
  • java 8
  • sts 4
  • docker to host mariadb, rabbitmq and zipkin (no services run docker)
  • Using spring boot cloud discovery based on Eureka for service discovery

Everything worked fine until the docker update today, after the docker upgrade

Eureka returns "host.docker.internal" as the hostname for my development box (machine hosting the spring boot cloud services)

This has worked fine until the docker updgrade on windows 10 today.

Any guidance on this one?

------------------------------ Details ----------------------------

"

---------------- Versions of spring ----------

buildscript {
    ext {
        springCloudVersion = "Greenwich.SR1"
        springBootVersion = "2.1.5.RELEASE"
        springRetryVersion = "1.2.4.RELEASE"
        lombokVersion = "3.6.4"
        mySqlConnectorVersion = "8.0.15"
        springBootAdminVersion = "2.1.5"

    }

I am using windows 10 enterprise for java development.

I use docker-compose to host mariadb, zipkin, and rabbitmq in my dev env on my windows 10 box

I have a multi-project gradle build with 8 spring boot cloud services

One of the services is a spring cloud discovery service hosting Eureke

The other spring cloud services are eureka clients.

Until today, everything worked 1) Eureka spring boot cloud services are started first 2) Other spring boot cloud services that are clients of the eclipse startup, register and query the spring cloud discovery client code to obtain the URL of the other services

Today, The latest docker for windows 10 was pushed out, and I installed it (I have been developing this app through several other docker updates).

I updated docker, did a reboot.

After the reboot, The Eureka server is returning "host.docker.internal" as the hostname in the URL instead of http:/mymachinename:8080

I don't have the network data before the upgrade, but now it is

U:\>ipconfig

Windows IP Configuration


Ethernet adapter vEthernet (DockerNAT):

   Connection-specific DNS Suffix  . :
   IPv4 Address. . . . . . . . . . . : 10.0.75.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : net.FOO.BAR.com
   IPv4 Address. . . . . . . . . . . : 146.122.145.71
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 146.122.145.1

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . :
   IPv4 Address. . . . . . . . . . . : 172.28.74.49
   Subnet Mask . . . . . . . . . . . : 255.255.255.240
   Default Gateway . . . . . . . . . :

My client application.properties file is:

eureka.client.serviceUrl.defaultZone= http://${ci2.srvhost}:8761/eureka/
eureka.instance.hostname=${ci2.srvhost}
spring.cloud.client.hostname=${ci2.srvhost}

Server application.property file

server.port=8761


eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF


Standard reboot after docker updated



The expected URL from discovery is

http://mymachine:8091

returned value after docker upgrade

http://host.docker.internal:8091


Solution 1:[1]

Thanks for the tip on the host file on windows

I found that docker adds aliases in the host file for host.docker.internal and gateway.docker.internal.

I am guessing that Eureka does a host lookup from the IP and host.docker.internal is returned.

I am not an expert at hosts files, but I added an alias for my actual host name to my IP (note: we use static ip's). After doing this, docker did not change my host file on reboot and the reverse lookup of the ip->host now returns my machine name instead of host.docker.internal

------------------ modified hosts file for windows

#I added an alias from my machine name to the IP before the docker added aliases
#
146.122.145.71 mymachine.net.foo.com
# Added by Docker Desktop
146.122.145.71 host.docker.internal
146.122.145.71 gateway.docker.internal

Solution 2:[2]

I was facing a similar issue where the eureka server was registering the services at host.docker.internal instead of localhost.

The issue in my case was an altered host file at location C:\Windows\System32\Drivers\etc\hosts. I deleted all the lines in the host file and saved it using npp with admin privilege. Restart the server post this change.

Looks like 'Docker Desktop' was changing the hostfile.

Solution 3:[3]

It the application.properties file for each eureka client , I added/changed

------------------ client

......

ci2.srvhost = my hostname

#to find this list,run ipconfig in command prompt
spring.cloud.inetutils.preferredNetworks=146.122,10.0

eureka.client.serviceUrl.defaultZone= http://${ci2.srvhost}:8761/eureka/
eureka.instance.hostname=${ci2.srvhost}
spring.cloud.client.hostname=${ci2.srvhost}

-------------------- eureka server application.property--------------------

# host to set of ci2 services
ci2.srvhost = ${COMPUTERNAME}


# on windows 10 boxes, running docker, we have to include preferred networks, 
# this is not needed on linux, or windows boxes not running docker
spring.cloud.inetutils.preferredNetworks=146.122,10.0

-------------------- standard config, should not need to change below -------------------

server.port=8761


eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

eureka.instance.hostname=${ci2.srvhost}
eureka.instance.prefer-ip-address=true

logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF

serviceUrl.defaultZone= http://${eureka.instance.hostname}:${server.port}/eureka/

Solution 4:[4]

Solution for Window 10: You don't have to remove all the lines from hosts files. Just comment this if exists (#192.168.1.4 host.docker.internal) (as we use this when playing with docker) And paste this (127.0.0.1 host.docker.internal) It worked for me.

Solution 5:[5]

"message": "Connection refused: no further information: host.docker.internal in eureka gateway error

Resolution:

check ping host.docker.internal response is some ip addresses apart form local host i,e 127.0.0.1 remove the C:\Windows\System32\Drivers\etc\hosts.file entries , make it empty

then restart eureka and your microservice instance.

also will find the message like below in the log this ensures you are registered in eureka

DiscoveryClient_BEER-SERVICE/DESKTOP-G2AIGG1:beer-service: splitting the above log message which denotes discovery client BEER-SERVICE is my service and DESKTOP-G2AIGG1 is my pc name beer-service is the service registered.

Solution 6:[6]

I was also facing the same issue, when I was loadbalancing my restTemplate. Something like this

@Bean
@LoadBalanced
RestTemplate restTemplate() {
return new RestTemplate();}

This is because of the ribbon client. So, without making any changes in the host file, when i deleted this code and made use of RestTemplateBuilder to get restTemplate, everything was working fine. Code Example:

@Autowired
private RestTemplateBuilder restTemplateBuilder;

RestTemplate restTemplate = restTemplateBuilder.build();

You can try this approach as well.

Solution 7:[7]

Was facing a similar issue as well. The problem was in Avast Premium Security. Try to disable Avast Firewall service.

With disabled firewall Eureka works fine event with host.docker.internal in the hosts file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael Schneider
Solution 2 Tibebes. M
Solution 3 Michael Schneider
Solution 4 Paras Girdher
Solution 5 Mohan Kumar L N
Solution 6 Ankur Mukherjee
Solution 7