将服务发布到docker swarm后发现eureka 客户端暴露出来的ip不可连接。
原因: docker swarm 集群发布后,docker 容器默认有3个网卡 ,eth0 ,eth1,eth2
其中overlay 占用了两个,vip 模式其中只有一个ip是可用的,因此暴露了不可用ip将会出现问题。
解决方案
Specifying a custom network value in Docker swarm and using spring.cloud.inetutils.preferredNetworks property
Using
eureka.instance.hostName: service-name
and
eureka.instance.preferIpAddress: false
where service-name is the same service-name specified in the Docker compose file
相关问题链接
https://github.com/spring-cloud/spring-cloud-netflix/issues/1820
https://stackoverflow.com/questions/43665011/microservice-registration-with-eureka-replicas-in-docker-swarm-cluster
https://stackoverflow.com/questions/51846960/spring-boot-eureka-in-docker-swarm-registering-wrong-internal-docker-ips
方法二:
instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
快来成为我的朋友或合作伙伴,一起交流,一起进步!
QQ群:961179337
微信:lixiang6153
邮箱:lixx2048@163.com
公众号:IT技术快餐
更多资料等你来拿!