我有两个罐子:“ 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-compose up)运行它们。
我应该改变什么?
固定的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
答案 0 :(得分:0)
尝试此配置:
eureka.client.serviceUrl.defaultZone=http://192.168.1.169:8761/eureka