简体   繁体   English

spring 启动云 eurka windows 10 eurkea 在最新的 docker 升级后返回 host.docker.internal 作为客户端主机名

[英]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) Spring 引导云发现问题,在 windows 10 上升级 docker 后 Eureka 主机名出现问题。(注意:docker 不托管 spring 服务,仅托管 mariadb、88580zip6 和 8838kin)

Summary概括

  • I am developing on windows 10 enterpise, latest patch我正在开发 windows 10 enterpise,最新补丁
  • java 8 java 8
  • sts 4 4级
  • docker to host mariadb, rabbitmq and zipkin (no services run docker) docker 托管 mariadb、rabbitmq 和 zipkin(没有服务运行 docker)
  • Using spring boot cloud discovery based on Eureka for service discovery使用基于Eureka的spring启动云发现进行服务发现

Everything worked fine until the docker update today, after the docker upgrade一切正常,直到今天 docker 更新,在 docker 升级之后

Eureka returns "host.docker.internal" as the hostname for my development box (machine hosting the spring boot cloud services) Eureka 返回“host.docker.internal”作为我的开发箱的主机名(托管 spring 启动云服务的机器)

This has worked fine until the docker updgrade on windows 10 today.这在今天 windows 10 上的 docker 升级之前一直运行良好。

Any guidance on this one?关于这个的任何指导?

------------------------------ Details ---------------------------- - - - - - - - - - - - - - - - 细节 - - - - - - - - - - ----------

"

---------------- Versions of spring ---------- -------------- 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.我正在使用 windows 10 企业进行 java 开发。

I use docker-compose to host mariadb, zipkin, and rabbitmq in my dev env on my windows 10 box我使用 docker-compose 在我的 windows 10 盒子上的开发环境中托管 mariadb、zipkin 和 rabbitmq

I have a multi-project gradle build with 8 spring boot cloud services我有一个多项目 gradle 构建 8 spring 启动云服务

One of the services is a spring cloud discovery service hosting Eureke其中一项服务是托管 Eureke 的 spring 云发现服务

The other spring cloud services are eureka clients.其他spring个云服务是eureka客户端。

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直到今天,一切正常 1)Eureka spring启动云服务先启动 2)其他spring启动云服务是eclipse启动的客户端,注册查询spring云发现客户端代码,获取其他服务的URL

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).今天,最新的 docker for windows 10 推出了,我安装了它(我一直在通过其他几个 docker 更新开发这个应用程序)。

I updated docker, did a reboot.我更新了 docker,重新启动。

After the reboot, The Eureka server is returning "host.docker.internal" as the hostname in the URL instead of http:/mymachinename:8080重启后,Eureka 服务器返回“host.docker.internal”作为 URL 中的主机名,而不是 http:/mymachinename:8080

I don't have the.network data before the upgrade, but now it is升级前没有.network数据,现在有了

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:我的客户端 application.properties 文件是:

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

Server application.property file服务器 application.property 文件

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

I was facing a similar issue where the eureka server was registering the services at host.docker.internal instead of localhost.我遇到了类似的问题,尤里卡服务器在 host.docker.internal 而不是 localhost 上注册服务。

The issue in my case was an altered host file at location C:\\Windows\\System32\\Drivers\\etc\\hosts.我的问题是在 C:\\Windows\\System32\\Drivers\\etc\\hosts 位置更改了主机文件。 I deleted all the lines in the host file and saved it using npp with admin privilege.我删除了主机文件中的所有行,并使用具有管理员权限的 npp 保存它。 Restart the server post this change.重新启动服务器发布此更改。

Looks like 'Docker Desktop' was changing the hostfile.看起来“Docker Desktop”正在更改主机文件。

It the application.properties file for each eureka client , I added/changed它是每个尤里卡客户端的 application.properties 文件,我添加/更改

------------------ 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-------------------- --------------------尤里卡服务器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/

Thanks for the tip on the host file on windows感谢有关 Windows 主机文件的提示

I found that docker adds aliases in the host file for host.docker.internal and gateway.docker.internal.我发现 docker 在主机文件中为 host.docker.internal 和 gateway.docker.internal 添加了别名。

I am guessing that Eureka does a host lookup from the IP and host.docker.internal is returned.我猜 Eureka 从 IP 进行主机查找并返回 host.docker.internal 。

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).我不是主机文件方面的专家,但我为我的实际主机名添加了一个别名到我的 IP(注意:我们使用静态 ip)。 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执行此操作后,docker 在重新启动时没有更改我的主机文件,并且 ip->host 的反向查找现在返回我的机器名称而不是 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 for Window 10: You don't have to remove all the lines from hosts files. Window 10 的解决方案:您不必从主机文件中删除所有行。 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.如果存在就评论这个(#192.168.1.4 host.docker.internal)(因为我们在玩docker时使用这个)并粘贴这个(127.0.0.1 host.docker.internal)它对我有用。

"message": "Connection refused: no further information: host.docker.internal in eureka gateway error “消息”:“连接被拒绝:没有更多信息:尤里卡网关错误中的host.docker.internal

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检查 ping host.docker.internal 响应是除本地主机之外的一些 ip 地址,即 127.0.0.1 删除 C:\\Windows\\System32\\Drivers\\etc\\hosts.file 条目,使其为空

then restart eureka and your microservice instance.然后重新启动 eureka 和您的微服务实例。

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. DiscoveryClient_BEER-SERVICE/DESKTOP-G2AIGG1:beer-service:拆分上面的日志消息,表示发现客户端 BEER-SERVICE 是我的服务,DESKTOP-G2AIGG1 是我的电脑名称 beer-service 是注册的服务。

I was also facing the same issue, when I was loadbalancing my restTemplate.当我对 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.因此,在没有对主机文件进行任何更改的情况下,当我删除此代码并使用RestTemplateBuilder获取 restTemplate 时,一切正常。 Code Example:代码示例:

@Autowired
private RestTemplateBuilder restTemplateBuilder;

RestTemplate restTemplate = restTemplateBuilder.build();

You can try this approach as well.您也可以尝试这种方法。

Was facing a similar issue as well.也面临着类似的问题。 The problem was in Avast Premium Security .问题出在Avast Premium Security中。 Try to disable Avast Firewall service.尝试禁用 Avast防火墙服务。

With disabled firewall Eureka works fine event with host.docker.internal in the hosts file.在禁用防火墙的情况下,Eureka 可以在主机文件中使用host.docker.internal正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Windows上使用Docker开发Spring Boot应用程序,但在Ubuntu VM上运行Docker容器(作为Docker主机) - Developing a spring boot application with docker on windows but run the docker container on a Ubuntu VM (as Docker Host) docker中的Spring应用程序如何访问主机或云mysql中的mysql? - How can a Spring app in docker access mysql in host or cloud mysql? 从 Z0F4137ED15025B504542Z85B 主机向在 docker 容器中运行的 spring api 发出请求 - Make a request to a spring api running in a docker container from windows host Docker Compose中的Spring Cloud Gateway返回ERR_NAME_NOT_RESOLVED - Spring Cloud Gateway in Docker Compose returns ERR_NAME_NOT_RESOLVED Spring Boot升级到最新版本 - Spring Boot Upgrade to Latest 如何使用spotify docker client连接到主机上的docker守护程序 - How to connect to the docker daemon on the host using spotify docker client 升级后,使用内部主机名而不是转发主机生成的Hateoas链接 - Hateoas links generated with internal hostname instead of forwarded host after upgrade 如何托管 Spring Boot 应用程序 - How to host a Spring Boot application 从单个主机注册Spring Boot Eureka Client的多个实例 - Register multiple Instances of a Spring Boot Eureka Client from a single host Docker春季启动OAuth - Docker spring boot oauth
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM