2019.06.12 Docker启动SpringCloud项目后注册服务失败

开发工具:IntelliJ IDEA 2019.1.3

问题描述:

使用Dockerfile指令生成Eureka的镜像文件和容器,并正常启动。同理启动Zipkin的时候,却无法正常注册服务,Eureka也检测不到服务

原因:

Eureka在Docker启动后,使用的是容器的IP地址,因此Zipkin打包时,如果使用的是127.0.0.1,则无法正常注册服务,所有需要修改。

解决方案:

一、获取Eureka容器的IP地址

  • 1.1 使用 docker exec -it [eureka容器id] bash 进入eureka注册中心的docker容器中
 docker exec -it   [eureka容器id]  bash
  • 1.2 使用cat /etc/hosts命令查看容器的IP地址
cat /etc/hosts
172.17.0.2就是Eureka在容器中的IP地址

二、修改连接Eureka的配置文件

eureka:
  instance:
    prefer-ip-address: true
  client:
    service-url:
      defaultZone: http://172.17.0.2:8888/eureka/
      register-with-eureka: true

三、重新打包Zipkin, 重启即可正常注册服务

你可能感兴趣的:(2019.06.12 Docker启动SpringCloud项目后注册服务失败)