0
votes

i have a simple spring cloud project,and it contains 4 services:

  • config:8888
  • registry(eureka):8761
  • gateway(zuul):8080
  • service-1:9527

enter image description here

the project has no problem if deployed in localhost,

i can successfully fetch service-1's api by zuul without docker:

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

but when i deployed with docker, it throws error: Caused by: java.lang.RuntimeException: org.apache.http.conn.HttpHostConnectException: Connect to registry:9527 [registry/172.21.0.4] failed: Connection refused (Connection refused)

i can only fetch with service-1's api

http://localhost:9527/test

PS: the two services(gateway,service-1) has been success registry to eureka

here is my 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

can anyone help me?

1
There seems to be a config error with the gateway. It is trying to connect to registry:9527. Can you provide the application.properties for the gateway.yamenk
i set the easiest config for gateway , just set server.port:8080 and spring.application.name:gateway, the other config is default,it is all work except fetching api by zuul in dockerjomalone_jia

1 Answers

0
votes

i have solved this issue , i forgot add @EnableDiscoveryClient on gateway main class,and cover the eureka instance hostname