简体   繁体   中英

Eureka client unable to register service to eureka server

I have two jars: "Eureka" and "Webportal".
I've tried to run them inside two docker container (using docker-compose).
I get an error from Webportal service container: 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)
- wget http://192.168.1.169:8761 (get the home page of eureka service).

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.

This is my docker-compose file:

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:

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).

What should i change?

EDIT

Fixed Webportal propeties file:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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