spring - 将挂载 Spring 微服务与 Docker 绑定导致 Eureka 未发现其他服务
问题描述
我之前为每个 Spring 微服务构建了一个 Docker 映像,在docker-compose.yml
文件中,这是我为启动它们所做的,并通过覆盖defaultZone
传递容器的名称让 Eureka 的服务注册了一些其他服务:
version: '3'
services:
eureka-discovery:
image: eureka-discovery-service:0.0.1
ports:
- 8761:8761
zuul-gateway:
image: zuul-gateway-service:0.0.1
environment:
- eureka.client.serviceUrl.defaultZone=http://eureka-discovery:8761/eureka
depends_on:
- eureka-discovery
ports:
- 8765:8765
有效。现在,我做了一些不同的事情,将我的项目绑定到本地开发容器中:
version: '3.1'
services:
eureka-discovery-service:
container_name: eureka-discovery-service
image: openjdk:11.0.9.1-jdk
ports:
- 8761:8761
volumes:
- ./eureka-discovery-service:/usr/src/app
working_dir: /usr/src/app
command: ./mvnw spring-boot:run
zuul-gateway-service:
container_name: zuul-gateway-service
image: openjdk:11.0.9.1-jdk
environment:
- eureka.client.serviceUrl.defaultZone=http://eureka-discovery-service:8761/eureka
ports:
- 8765:8765
volumes:
- ./zuul-gateway-service:/usr/src/app
working_dir: /usr/src/app
command: ./mvnw spring-boot:run
depends_on:
- eureka-discovery-service
links:
- eureka-discovery-service
但是有了这样的事情,看起来zuul-gateway-service
不像eureka-discovery-service
以前那样。
2020-12-17 23:26:29.997 错误 78 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_ZUUL-GATEWAY-SERVICE/7c580b412063:zuul-gateway-service:8765 - 无法刷新其缓存!status = 无法在任何已知服务器上执行请求
我注意到它使用的是 Eureka 容器的 ID 而不是它的名称。
解决方案
command
我设法通过更改并覆盖那里的属性而不是 on来使其工作environments
:
command: ./mvnw spring-boot:run -Dspring-boot.run.arguments=--eureka.client.serviceUrl.defaultZone=http://eureka-discovery-service:8761/eureka
如果有更好的方法,我想知道。
推荐阅读
- redis - 在执行事务之前使用来自 jedis 事务响应的结果
- javascript - 尝试从 JavaScript 中的 localStorage 查找现有产品时出错
- python - 有没有关于 spyder 报告的文档?
- c++ - 如何在 C++17 中制作模板包装器/装饰器
- shopify - 使用 shopify 液体获取索引(主页)页面产品
- mysql - SQL OR 返回两个表达式
- wifi - 如何在 AsyncTask 的 doInBackground 方法中获取共享首选项
- ionic-framework - 如何使用 Ionic App 的自定义 URL 方案启动外部打开的应用程序?
- vba - 无法过滤 BookingID 的号码和重复
- sharepoint - 使用 REST oData url 访问共享点子站点的列表项