![](/img/trans.png)
[英]Developing a spring boot application with docker on windows but run the docker container on a Ubuntu VM (as Docker Host)
[英]spring boot cloud eurka windows 10 eurkea returns host.docker.internal for client host name after latest docker upgrade
Spring 引导云发现问题,在 windows 10 上升级 docker 后 Eureka 主机名出现问题。(注意:docker 不托管 spring 服务,仅托管 mariadb、88580zip6 和 8838kin)
概括
一切正常,直到今天 docker 更新,在 docker 升级之后
Eureka 返回“host.docker.internal”作为我的开发箱的主机名(托管 spring 启动云服务的机器)
这在今天 windows 10 上的 docker 升级之前一直运行良好。
关于这个的任何指导?
- - - - - - - - - - - - - - - 细节 - - - - - - - - - - ----------
“
-------------- 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"
}
我正在使用 windows 10 企业进行 java 开发。
我使用 docker-compose 在我的 windows 10 盒子上的开发环境中托管 mariadb、zipkin 和 rabbitmq
我有一个多项目 gradle 构建 8 spring 启动云服务
其中一项服务是托管 Eureke 的 spring 云发现服务
其他spring个云服务是eureka客户端。
直到今天,一切正常 1)Eureka spring启动云服务先启动 2)其他spring启动云服务是eclipse启动的客户端,注册查询spring云发现客户端代码,获取其他服务的URL
今天,最新的 docker for windows 10 推出了,我安装了它(我一直在通过其他几个 docker 更新开发这个应用程序)。
我更新了 docker,重新启动。
重启后,Eureka 服务器返回“host.docker.internal”作为 URL 中的主机名,而不是 http:/mymachinename:8080
升级前没有.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 . . . . . . . . . :
我的客户端 application.properties 文件是:
eureka.client.serviceUrl.defaultZone= http://${ci2.srvhost}:8761/eureka/
eureka.instance.hostname=${ci2.srvhost}
spring.cloud.client.hostname=${ci2.srvhost}
服务器 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
我遇到了类似的问题,尤里卡服务器在 host.docker.internal 而不是 localhost 上注册服务。
我的问题是在 C:\\Windows\\System32\\Drivers\\etc\\hosts 位置更改了主机文件。 我删除了主机文件中的所有行,并使用具有管理员权限的 npp 保存它。 重新启动服务器发布此更改。
看起来“Docker Desktop”正在更改主机文件。
它是每个尤里卡客户端的 application.properties 文件,我添加/更改
- - - - - - - - - 客户
......
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}
--------------------尤里卡服务器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
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/
感谢有关 Windows 主机文件的提示
我发现 docker 在主机文件中为 host.docker.internal 和 gateway.docker.internal 添加了别名。
我猜 Eureka 从 IP 进行主机查找并返回 host.docker.internal 。
我不是主机文件方面的专家,但我为我的实际主机名添加了一个别名到我的 IP(注意:我们使用静态 ip)。 执行此操作后,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
Window 10 的解决方案:您不必从主机文件中删除所有行。 如果存在就评论这个(#192.168.1.4 host.docker.internal)(因为我们在玩docker时使用这个)并粘贴这个(127.0.0.1 host.docker.internal)它对我有用。
“消息”:“连接被拒绝:没有更多信息:尤里卡网关错误中的host.docker.internal
解析度:
检查 ping host.docker.internal 响应是除本地主机之外的一些 ip 地址,即 127.0.0.1 删除 C:\\Windows\\System32\\Drivers\\etc\\hosts.file 条目,使其为空
然后重新启动 eureka 和您的微服务实例。
还会在日志中找到如下消息,这确保您已在尤里卡注册
DiscoveryClient_BEER-SERVICE/DESKTOP-G2AIGG1:beer-service:拆分上面的日志消息,表示发现客户端 BEER-SERVICE 是我的服务,DESKTOP-G2AIGG1 是我的电脑名称 beer-service 是注册的服务。
当我对 restTemplate 进行负载平衡时,我也面临着同样的问题。 像这样的东西
@Bean
@LoadBalanced
RestTemplate restTemplate() {
return new RestTemplate();}
这是因为功能区客户端。 因此,在没有对主机文件进行任何更改的情况下,当我删除此代码并使用RestTemplateBuilder
获取 restTemplate 时,一切正常。 代码示例:
@Autowired
private RestTemplateBuilder restTemplateBuilder;
RestTemplate restTemplate = restTemplateBuilder.build();
您也可以尝试这种方法。
也面临着类似的问题。 问题出在Avast Premium Security中。 尝试禁用 Avast防火墙服务。
在禁用防火墙的情况下,Eureka 可以在主机文件中使用host.docker.internal正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.