spring cloud无法在docker中从zuul获取服务

时间:2017-12-13 06:22:18

标签: docker spring-cloud netflix-eureka netflix-zuul spring-cloud-netflix

我有一个简单的Spring云项目,它包含4项服务:

  • 配置:8888
  • 注册表(尤里卡):8761
  • 网关(zuul):8080
  • 服务-1:9527

enter image description here

如果在localhost中部署项目没有问题,

我可以通过zuul成功获取service-1的api而无需使用docker:

  

http://localhost:8080/service-1/test

但是当我使用docker部署时, 它抛出错误:Caused by: java.lang.RuntimeException: org.apache.http.conn.HttpHostConnectException: Connect to registry:9527 [registry/172.21.0.4] failed: Connection refused (Connection refused)

我只能使用service-1的api

获取
  

http://localhost:9527/test

PS:两个服务(网关,服务-1)已成功注册到eureka

这是我的docker-compose yml:

version: '3'
services:
  config:
    build: ./config
    ports:
      - "8888:8888"
  registry:
    build: ./registry
    ports:
      - "8761:8761"
    depends_on:
      - config
    environment:
      - SPRING_PROFILES_ACTIVE=prd
  gateway:
    build: ./gateway
    depends_on:
      - config
    links:
      - registry
      - service-1
    ports:
      - "8080:8080"
    environment:
      - SPRING_PROFILES_ACTIVE=prd
  service-1:
    build: ./service-1
    ports:
      - "9527:9527"
    depends_on:
      - config
    links:
      - registry
    environment:
      - SPRING_PROFILES_ACTIVE=prd

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题,我忘了在网关主类上添加@EnableDiscoveryClient,并覆盖eureka实例主机名