如何解决Eureka客户端注册在Docker中失败:无法注册为客户端-但eureka服务器和客户端已分别启动并运行
我有一个用于 Eureka Server 的Spring Boot应用程序:
application.yml(Eureka服务器)
server:
port: 8761
spring:
application:
name: eureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
application.yml(Eureka客户端-microservice2)
spring:
application:
name: second-feign-client
server:
port: 8082
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
Dockerfile :(对于eureka-server应用程序和microservice2应用程序都是相同的)
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
copY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
在本地,Eureka客户端, microservice2 ,已在Eureka Server上完美注册。两者都是Spring Boot应用程序。我已经将两个应用程序都进行了docker化,并推送至docker hub。我正在尝试在docker-compose中运行这两个应用程序,但是eureka客户端无法使用docker-compose在eureka服务器中注册。
我收到此错误:
microservice2_1 | 2020-09-07 13:56:36.149 ERROR 1 --- [freshExecutor-0] com.netflix.discovery.discoveryClient : D
iscoveryClient_SECOND-FEIGN-CLIENT/379b7c698e87:second-feign-client:8082 - was unable to refresh its cache! status =
Cannot execute request on any kNown server
microservice2_1 |
microservice2_1 | com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any kNown ser
ver
microservice2_1 | at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(Retryab
leEurekaHttpClient.java:112) ~[eureka-client-1.9.25.jar!/:1.9.25]
microservice2_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications
(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.25.jar!/:1.9.25]
microservice2_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(Eurek
aHttpClientDecorator.java:137) ~[eureka-client-1.9.25.jar!/:1.9.25]
microservice2_1 | at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(Session
edEurekaHttpClient.java:77) ~[eureka-client-1.9.25.jar!/:1.9.25]
microservice2_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications
(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.25.jar!/:1.9.25]
microservice2_1 | at com.netflix.discovery.discoveryClient.getAndStoreFullRegistry(discoveryClient.java:1097) [
eureka-client-1.9.25.jar!/:1.9.25]
microservice2_1 | at com.netflix.discovery.discoveryClient.fetchRegistry(discoveryClient.java:1011) [eureka-cli
ent-1.9.25.jar!/:1.9.25]
microservice2_1 | at com.netflix.discovery.discoveryClient.refreshRegistry(discoveryClient.java:1533) [eureka-c
lient-1.9.25.jar!/:1.9.25]
microservice2_1 | at com.netflix.discovery.discoveryClient$CacheRefreshThread.run(discoveryClient.java:1500) [e
ureka-client-1.9.25.jar!/:1.9.25]
microservice2_1 | at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_212]
microservice2_1 | at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_212]
microservice2_1 | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_
212]
microservice2_1 | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_
212]
microservice2_1 | at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
microservice2_1 |
eureka-server_1 | 2020-09-07 13:56:39.393 INFO 1 --- [a-evictionTimer] c.n.e.registry.AbstractInstanceRegistry : R
unning the evict task with compensationTime 0ms
我经历了已经讨论过的相关问题 docker-eureka-spring-boot 我已经尝试了所有这些讨论过的选项,但仍然无法使用。
docker-compose.yml
version: "3.8"
services:
eureka-server:
image: dineshdontha67/eureka-server:latest
ports:
- "8761:8761"
networks:
- ms-network
microservice2:
image: dineshdontha67/microservice2:latest
ports:
- "8082:8082"
networks:
- ms-network
depends_on:
- eureka-server
environment:
server.port: 8082
eureka.instance.hostname: localhost
eureka.client.enabled: 'true'
#EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://localhost:8761/eureka
# networks:
# - ms-network
# depends_on:
# - eureka-server
# server.port: 8082
# eureka.host: eureka-server
# eureka.client.enabled: 'true'
# eureka.instance.preferIpAddress: 'true'
networks:
ms-network:
driver: bridge
注意:泊坞窗组成后,两个spring boot应用程序都可以正常运行,但是只有注册失败。
E:\eureka-server>docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------------------
eureka-server_eureka-server_1 java -jar /app.jar Up 0.0.0.0:8761->8761/tcp
eureka-server_microservice2_1 java -jar /app.jar Up 0.0.0.0:8082->8082/tcp
参考回执:
microservices2 git repo(充当eureka客户端):microservices2
eureka服务器git repo(充当eureka服务器):eureka-server
请帮助我。多谢!
解决方法
version: "3.8"
services:
eureka-server:
image: dineshdontha67/eureka-server:latest
ports:
- "8761:8761"
networks:
- ms-network
environment:
eureka.instance.hostname: eureka-server
eureka.client.serviceUrl.defaultZone: http://eureka-server:8761/eureka/
microservice2:
image: dineshdontha67/microservice2:latest
ports:
- "8082:8082"
networks:
- ms-network
depends_on:
- eureka-server
environment:
server.port: 8082
eureka.client.serviceUrl.defaultZone: http://eureka-server:8761/eureka/
#EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://localhost:8761/eureka
# networks:
# - ms-network
# depends_on:
# - eureka-server
# server.port: 8082
# eureka.host: eureka-server
# eureka.client.enabled: 'true'
# eureka.instance.preferIpAddress: 'true'
networks:
ms-network:
driver: bridge
根据您的服务名称覆盖主机名
欢呼
,version: "3.8"
networks:
ms-network:
name: ms-network
driver: bridge
services:
eureka-server:
image: dineshdontha67/eureka-server:latest
ports:
- "8761:8761"
networks:
- ms-network
environment:
eureka.instance.hostname: eureka-server
eureka.client.serviceUrl.defaultZone: http://eureka-server:8761/eureka
microservice2:
image: dineshdontha67/book-service:latest
ports:
- "8082:8080"
networks:
- ms-network
depends_on:
- eureka-server
environment:
server.port: 8082
eureka.client.serviceUrl.defaultZone: http://eureka-server:8761/eureka
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。