试图连接docker容器中的服务到docker容器中的eureka的异常



我正在尝试连接一个docker容器中的eureka客户端到另一个docker容器中的eureka服务器。

我正在尝试通过在

中设置的服务名称进行连接在我的docker docker-compose.yaml

services:
eureka-server:
image:  eurekaservice
hostname: eureka-server
container_name: eurekahost
ports:
- "8761:8761"

在我的eureka属性文件中有

spring.application.name=eureka-service
server.port=8761
eureka.client.registerWithEureka = false
eureka.client.fetchRegistry = false
eureka.instance.hostname=eurekahost
eureka.client.serviceUrl.defaultZone  = http://eurekahost:8761/eureka

在我的eureka客户端属性文件中,我有

server.port=8080
spring.application.name=user-service
eureka.client.registerWithEureka = true
eureka.client.fetchRegistry = true
eureka.client.serviceUrl.defaultZone  = http://eurekahost:8761/eureka
eureka.client.instance.preferIpAddress = false
eureka.instance.hostname= eurekahost

我用docker-compose up运行Eureka

然后我用 启动客户端服务docker run -p 8083:8080 bankuser

我得到以下异常

Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8761 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:376)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)

不知道我错过了什么

更新属性到yml文件,方便阅读

应用程序。Yml for eureka server

server:
port=8761
spring:
application: eureka-service
eureka:
instance:
hostname: eurekahost
client:
validateCertificates: false
registerWithEureka: false
fetchRegistry: false
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://eurekahost:8761/eureka

应用程序。Yml for eureka client

server:
port=8080
spring:
application: name=user-service
eureka:
instance:
hostname: eurekahost
client:
validateCertificates: true
registerWithEureka: true
fetchRegistry: true
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://eurekahost:8761/eureka
instance:
preferIpAddress: false

如果

相关内容

  • 没有找到相关文章

最新更新