EurekaServer com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server on Docker

假装没事ソ 提交于 2020-07-31 05:07:19

问题


Eureka server not working on Docker compose

Here is the docker-compose for the Eureka server and config server

version: '3'
services:
    fetebird-eurekaservice:
        container_name: FeteBird-EurekaService
        build:
            context: ../../Eureka-Service-Registry/
            dockerfile: Dockerfile
        image: fetebird/eurekaservice
        ports:
            - "8761:8761"
        networks:
            - spring-cloud-network
        volumes:
            - ./fetebird-eurekaservice/data:/data
        logging:
            driver: json-file
    
    fetebird-configserver:
        container_name: FeteBird-ConfigServer
        build:
            context: ../../FeteBird-ConfigServer
            dockerfile: Dockerfile
        image: fetebird/configserver
        ports:
            - "8085:8085"
        networks:
            - spring-cloud-network
        volumes:
            - ./fetebird-configserver/data:/data
        logging:
            driver: json-file        

networks:
    spring-cloud-network:
        driver: bridge

I tried with the expose command as well but no luck

Eureka server docker file

FROM openjdk:14

WORKDIR /fetebird-eurekaservice/service

ADD build/libs/fete-bird-eureka-service-registry-0.0.1-SNAPSHOT.jar fete-bird-eureka-service-registry-0.0.1-SNAPSHOT.jar

ENTRYPOINT ["java", "-jar", "fete-bird-eureka-service-registry-0.0.1-SNAPSHOT.jar"]

Config server Client Docker file

FROM openjdk:14

WORKDIR /fetebird-eurekaservice/service

ADD build/libs/fete-bird-configuration-server-0.0.1-SNAPSHOT.jar fete-bird-configuration-server-0.0.1-SNAPSHOT.jar

ENTRYPOINT ["java", "-jar", "fete-bird-configuration-server-0.0.1-SNAPSHOT.jar"]

Config Server

@SpringBootApplication
@EnableEurekaServer
public class FeteBirdEurekaServiceRegistryApplication {
    public static void main(String[] args) {
        SpringApplication.run(FeteBirdEurekaServiceRegistryApplication.class, args);
    }
}

Configuration of Eureka server

application.yml

server:
  port: 8761

eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
spring:
  profiles:
    active: dev

bootstrap.yml

spring:
  application:
    name: CONFIG-SERVER
  profiles:
    active: native
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/config

Config Server

server: port: 8085

Discovery Server Access

eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://localhost:8761/eureka/
  instance:
    hostname: localhost

Errors

com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
FeteBird-ConfigServer     |     at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer     |     at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer     |     at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer     |     at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer     |     at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer     |     at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:857) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer     |     at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:121) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer     |     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
FeteBird-ConfigServer     |     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
FeteBird-ConfigServer     |     at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
FeteBird-ConfigServer     |     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
FeteBird-ConfigServer     |     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
FeteBird-ConfigServer     |     at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
FeteBird-ConfigServer     | 
FeteBird-ConfigServer     | 2020-07-20 14:30:19.268  WARN 1 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator     : There was a problem with the instance info replicator

回答1:


The problem is this

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:1111/eureka

It is pointing to localhost and Eureka is no longer running on localhost, localhost in this case is the individual containers. The containers are linked together so you can just change this to

eureka:
  client:
    serviceUrl:
      defaultZone: http://fetebird-eurekaservice:8761/eureka/
    instance:
      hostname: fetebird-eurekaservice

Each docker file

ENTRYPOINT ["java", "-jar", "fete-bird-configuration-server-0.0.1-SNAPSHOT.jar"] fetebird-eurekaservice

Docker compose file (Add links and depends_on)

fetebird-configserver:
        container_name: FeteBird-ConfigServer
        build:
            context: ../../FeteBird-ConfigServer
            dockerfile: Dockerfile
        image: fetebird/configserver
        ports:
            - "8085:8085"
        links:
            - fetebird-eurekaservice
        depends_on:
            - fetebird-eurekaservice
        networks:
            - spring-cloud-network
        volumes:
            - ./fetebird-configserver/data:/data
        logging:
            driver: json-file  

Reference - https://github.com/spring-cloud/spring-cloud-netflix/issues/2442



来源:https://stackoverflow.com/questions/62997711/eurekaserver-com-netflix-discovery-shared-transport-transportexception-cannot-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!