简体   繁体   English

Eureka客户端无法向Eureka服务器注册服务

[英]Eureka client unable to register service to eureka server

I have two jars: "Eureka" and "Webportal". 我有两个罐子:“ Eureka”和“ Webportal”。
I've tried to run them inside two docker container (using docker-compose). 我试图在两个docker容器中运行它们(使用docker-compose)。
I get an error from Webportal service container: com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server 我从com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server服务容器收到错误: com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
The containers are able to reach each other, i have checked it using: 容器能够相互到达,我已经使用以下方法进行了检查:
- docker exec -it {container_id} /bin/sh (attach console) docker exec -it {container_id} /bin/sh (附加控制台)
- wget http://192.168.1.169:8761 (get the home page of eureka service). wget http://192.168.1.169:8761 (获取eureka服务的主页)。

I've read that Eureka is not able to resolve hostname and a possibile workarond suggested from the community is to use the host machine ip. 我读到Eureka无法解析主机名,社区建议的可能的工作方式是使用主机ip。

This is my docker-compose file: 这是我的docker-compose文件:

version: '3'
services:
  mysql:
    container_name: project-mysql
    image: mysql/mysql-server:5.7
    ports:
    - "3306:3306"
    environment:
      MYSQL_DATABASE: project
      MYSQL_ROOT_PASSWORD: 
      MYSQL_ROOT_HOST: '%'
    restart: always

  redis:
    container_name: project-redis
    image: redis:alpine
    ports:
    - "6379:6379"
    restart: always

  eureka-server:
    container_name: project-eureka
    image: maven:3.5-jdk-8
    ports:
    - "8761:8761"
    working_dir: /service
    volumes:
    - ../project-eureka-service/target:/service
    command: java -jar /service/project-eureka-service-0.0.1-SNAPSHOT.jar
    restart: always
    depends_on:
    - redis
    - mysql

  webportal:
    container_name: project-webportal
    image: maven:3.5-jdk-8
    ports:
    - "9191:9191"
    working_dir: /service
    volumes:
    - ../project-webportal/target:/service
    command: java -jar /service/project-webportal-0.0.1-SNAPSHOT.jar
    restart: always
    depends_on:
    - eureka-server        
    links: 
    - eureka-server

networks:
  spring-cloud-network:
    driver: bridge

And this is my Webportal service configuration: 这是我的Webportal服务配置:

spring.application.name=webportal-service
server.port=9191
eureka.client.service-url.default-zone=http://192.168.1.169:8761/eureka
proxy-url=http://192.168.1.169:8762
endpoint.login=/user/login
endpoint.registration=/user/userRegistration
endpoint.log-chart.daily=/presentation/getUserLogDaily
endpoint.log-chart.weekly=/presentation/getUserLogWeekly
endpoint.log-chart.monthly=/presentation/getUserLogMonthly
endpoint.user-log=/presentation/getUserLog
endpoint.user-permission-list=/user/userPermissionList
eureka.instance.prefer-ip-address=true
eureka.instance.ip-address=192.168.1.169

With this configuration i'm able to run them from host machine (via java -jar) but not via docker (docker-compose up). 通过这种配置,我可以从主机(通过java -jar)运行它们,而不能通过docker(通过docker-compose up)运行它们。

What should i change? 我应该改变什么?

EDIT 编辑

Fixed Webportal propeties file: 固定的Webportal属性文件:

spring.application.name=webportal-service
server.port=9191
eureka.client.service-url.defaultZone=http://192.168.1.169:8761/eureka
proxy-url=http://192.168.1.169:8762
endpoint.login=/user/login
endpoint.registration=/user/userRegistration
endpoint.log-chart.daily=/presentation/getUserLogDaily
endpoint.log-chart.weekly=/presentation/getUserLogWeekly
endpoint.log-chart.monthly=/presentation/getUserLogMonthly
endpoint.user-log=/presentation/getUserLog
endpoint.user-permission-list=/user/userPermissionList

试试这个配置:

eureka.client.serviceUrl.defaultZone=http://192.168.1.169:8761/eureka

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM