我一直在研究docker与eureka,我以为我明白它是如何工作的,但相反,我混淆了我自己。
有一个用于eureka服务器的容器和一个用于eureka客户端的容器。eureka客户端需要能够访问eureka服务器。我所做的就是找到容器的IP地址在这个例子中是172.20.0.2所以我的尤利卡客户defaultZone: http://172.20.0.2:8761/尤里卡/
我已将两个服务连接到网络
"Containers": {
"128e40236b9dc7e45cd046e34a0e2d5851a24c6da4d9510003615079c6c07a1e": {
"Name": "bankhost",
"EndpointID": "c5fa49a2d2d17232fa03b38835430e10eb5f40017d092b80aa624f1245bf6ec1",
"MacAddress": "02:42:ac:14:00:03",
"IPv4Address": "172.20.0.3/16",
"IPv6Address": ""
},
"151bb21fbae965d782d0aca6fbae3cb7d24b19755bc1f01049a7e7579621e171": {
"Name": "eurekahost",
"EndpointID": "dd260aecffc3336b96ecfab3c7f3e36191a2672e67ca29390c359fb6b30feb2f",
"MacAddress": "02:42:ac:14:00:02",
"IPv4Address": "172.20.0.2/16",
"IPv6Address": ""
}
},
当我运行docker compose up为我的客户端服务,它运行,但我没有注册到Eureka
我的应用程序。
server:
port=8761
spring:
application: eureka-service
eureka:
client:
validateCertificates: false
registerWithEureka: false
fetchRegistry: false
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
my server docker- composer .yml
version: '3'
services:
eureka-server:
image: eurekaservice
hostname: eureka-server
container_name: eurekahost
ports:
- "8761:8761"
networks:
default:
external: true
name: opspec
我的应用程序。
server:
port=8080
spring:
application: name=user-service
eureka:
client:
validateCertificates: true
registerWithEureka: true
fetchRegistry: true
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://172.20.0.2:8761/eureka/
客户机docker-compose
version: '3'
services:
bank-server:
image: bankservice
hostname: bank-server
container_name: bankhost
ports:
- "8083:8080"
networks:
default:
external: true
name: opspec
我真正需要知道的是我需要在我的应用程序中放入什么。
for defaultZone: http://XXXXXXXXX:8761/eureka/
我只需要知道XXXXXXXX应该是什么,然后我就可以反写了。
是包含Eureka Server的容器的名称Eureka Server所在容器的IP地址镜像的服务名称甚至是0.0.0.0