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

Eureka client unable to register service to eureka server

我有两个罐子:"Eureka" 和 "Webportal"。
我试过 运行 它们在两个 docker 容器中(使用 docker-compose)。
我从 Webportal 服务容器收到错误消息:com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
容器能够相互接触,我已经使用以下方法检查过:
- docker exec -it {container_id} /bin/sh(附加控制台)
- wget http://192.168.1.169:8761(获取eureka服务首页)

我了解到 Eureka 无法解析主机名,社区建议的一种可能的解决方法是使用主机 ip。

这是我的 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

这是我的 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

使用此配置,我可以从主机(通过 java -jar)运行 它们,但不能通过 docker(docker-组合) .

我应该改变什么?

编辑

修复了 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