简体   繁体   English

EurekaServer com.netflix.discovery.shared.transport.TransportException:无法在 Docker 上的任何已知服务器上执行请求

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

Eureka server not working on Docker compose Eureka 服务器无法在 Docker 上运行

Here is the docker-compose for the Eureka server and config server这是 Eureka 服务器和配置服务器的 docker-compose

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我也尝试过使用expose命令,但没有运气

Eureka server docker file尤里卡服务器docker文件

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配置服务器客户端 Docker 文件

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应用程序.yml

server:
  port: 8761

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

bootstrap.yml引导程序.yml

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

Config Server配置服务器

server: port: 8085服务器:端口: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

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.它指向 localhost 并且 Eureka 不再在 localhost 上运行,在这种情况下 localhost 是单个容器。 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每个 docker 文件

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

Docker compose file (Add links and depends_on) Docker 撰写文件(添加链接和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://github.com/spring-cloud/spring-cloud-netflix/issues/2442

As pointed out by OP's answer: Eureka is no longer running on localhost, localhost in this case is the individual containers.正如 OP 的回答所指出的:Eureka 不再在 localhost 上运行,在这种情况下,localhost 是各个容器。

I'm here to introduce two addtional solutions:我在这里介绍两个额外的解决方案:

Solution 1. Using docker environment解决方案1.使用docker环境

Dev environment (in application.properties):开发环境(在 application.properties 中):

eureka.client.service-url.defaultZone = http://localhost:8761/eureka 

Docker environment (override defaultZone settings in docker-compose.yml file): Docker 环境(覆盖docker-compose.yml文件中的 defaultZone 设置):

myservice:
    container_name: myservice
    environment:
      eureka.client.service-url.defaultZone: http://<your-eureka-service-name>:8761/eureka

This will override application.properties or application.yml values.这将覆盖application.propertiesapplication.yml值。

If you'd like to override a bunch stuff in docker environment like jdbc connection, you can use SPRING_APPLICATION_JSON (spring will read it as it is embedded in an environment variable or system property):如果你想覆盖 docker 环境中的一堆东西,比如 jdbc 连接,你可以使用SPRING_APPLICATION_JSON (spring 会读取它,因为它嵌入在环境变量或系统属性中):

myservice:
    container_name: myservice
    environment:
      SPRING_APPLICATION_JSON: '{
        "spring.datasource.url=jdbc:mysql": "//jdbc:mysql:3306/mydb",
        "spring.datasource.username": "username",
        "spring.datasource.password": "password",
        "spring.jpa.hibernate.ddl-auto": "update",
        "eureka.client.service-url.defaultZone": "http://<your-eureka-service-name>:8761/eureka"
        }'

Solution 2. Setting up different profiles :解决方案 2. 设置不同的配置文件

Step one, prepare two versions of application.properties , if you prefer application.yml , your choise:第一步,准备两个版本的application.properties ,如果你更喜欢application.yml ,你的选择:

application-default.properties for dev environment:开发环境的application-default.properties

eureka.client.service-url.defaultZone = http://localhost:8761/eureka 

application-docker.properties for docker environment: docker 环境的application-docker.properties

eureka.client.service-url.defaultZone = http://<your-eureka-service-name>:8761/eureka

Step two (docker-compose file):第二步(docker-compose 文件):

myservice:
    container_name: myservice
    environment:
      SPRING_PROFILES_ACTIVE: docker

By setting up SPRING_PROFILES_ACTIVE to docker, it will load application-docker.properties as active profiles.通过将SPRING_PROFILES_ACTIVE设置为 docker,它将加载application-docker.properties作为活动配置文件。

References:参考:

  1. Spring Profiles Spring 型材

  2. Spring Environment-Specific Properties File Spring 环境特定属性文件

  3. How to load the SPRING_PROFILES_ACTIVE value in the client service dynamically? 如何动态加载客户端服务中的 SPRING_PROFILES_ACTIVE 值?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker compose com.netflix.discovery.shared.transport.TransportException:无法在任何已知服务器上执行请求 - Docker compose com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server 错误 - “com.netflix.discovery.shared.transport.TransportException:无法在任何已知服务器上执行请求” - Error - "com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server" com.netflix.discovery.shared.transport.TransportException:无法在任何已知服务器上执行请求 - com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server 尝试构建简单的微服务时出现错误“无法在任何已知服务器上执行请求” - Trying to build simple Microservice getting error " Cannot execute request on any known server" spring-boot eureka 客户端错误“无法在任何已知服务器上执行请求” - spring-boot eureka client error "Cannot execute request on any known server" Apache 运行 cassandra 和 .netflix.astyanax 库时出现 TransportException,没有任何特定的错误消息 - Apache TransportException when running cassandra and netflix.astyanax library without any specific error message 在启动时通过Netflix Eureka Discovery实现Spring Cloud Config Server循环依赖 - Spring Cloud Config Server Circular Dependency With Netflix Eureka Discovery on Startup net.schmizz.sshj.transport.TransportException:无法达成和解 - net.schmizz.sshj.transport.TransportException: Unable to reach a settlement 如何使用Netflix / Eureka Service的发现信息在Netflix / Zuul和Netflix / Ribbon中启用自动路由? - How to enable automatic routing in Netflix/Zuul and Netflix/Ribbon with discovery information from Netflix/Eureka Service? 响应类中的com.netflix.feign NullPointerException - com.netflix.feign NullPointerException in Response class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM