为什么部署在Docker容器上的Spring云Netflix应用程序需要明确设置eureka.instance.hostname?

一个简单的场景:

  • 2个尤里卡服务器( http:// archimedes1 http:// archimedes2 )
  • 1configuration服务器
  • 1 Zull网关
  • 1商业微服务

部署在本地一切都按预期工作。

我dockerized他们运行在每个应用程序的个别容器,并在Windows上的Dockertesting。

我在部署(config server,zull和b-ms)后看到的是,如果我没有为每个人指定eureka.instance.hostname ,他们会在Eureka服务器中注册一个无效的URL 。 这使得他们无法互相呼叫,因为他们得到无效的URL。

例如:

 CONFIGSERVER n/a (1) (1) UP (1) - 287dd3ada410:configserver:8888 

287dd3ada410:configserver:8888点在287dd3ada410:8888/info 。 而这并不存在。

解决这个问题,我必须添加到configserver的application.yml(和其他应用程序的等价物):

 eureka: instance: hostname: config-server 

现在它显示在这个尤里卡:

 CONFIGSERVER n/a (1) (1) UP (1) - c99cdfe9bd01:configserver:8888 

c99cdfe9bd01:configserver:8888指向http://config-server:8888/info ,现在可以正确parsingconfiguration服务器。

为什么有必要为每个服务使用eureka.instance.hostname 为什么不注册与他们的IP:端口运行时没有Docker( c99cdfe9bd01:configserver:8888 -> 192.168.99.100:8888 )?

我相信每个Docker容器都需要使用映射到容器端口的Docker主机IP和Docker主机端口进行注册。

这是我用过的:

尤里卡实例:

 docker run -idt -p 8001:8001 --net=host -e spring.profiles.active=peerAware -e appPort=8001 -e hostName=$HOSTNAME -e dataCenter=asimio-cloud-dal -e environment=staging -e peerUrls="http://$HOSTNAME:8002/eureka/" asimio/discovery-server:1.0.73 

服务实例:

 docker run -idt -p 8601:8601 --net=host -e appPort=8601 -e hostName=$HOSTNAME -e eureka.client.serviceUrl.defaultZone="http://$HOSTNAME:8001/eureka/,http://$HOSTNAME:8002/eureka/" asimio/demo-registration-api-2:1.0.21 

http://tech.asimio.net/2016/11/14/Microservices-Registration-and-Discovery-using-Spring-Cloud-Eureka-Ribbon-and-Feign.html#running-the-discovery-server-and-演示服务function于泊坞窗的容器