Spring Cloud Netflix和Docker Compose-无法向eureka注册服务 [英] Spring Cloud Netflix and Docker Compose - cannot register services with eureka
问题描述
我正在尝试使用docker-compose在本地(Ubuntu)运行2个简单服务:一个eureka服务器和一个配置服务器(这也是一个eureka客户端).两者都具有运行java -jar
的简单dockerfile,公开其端口并可以正常工作.我还尝试添加eureka.client.service-url.defaultZone=http://company-service-discovery:8761/eureka
来查看它是否可以注册,并且可以正常工作.
I'm trying to use docker-compose to run 2 simple services locally (Ubuntu): a eureka server, and config server (which is also a eureka client). Both of these have simple dockerfiles that run java -jar
, expose their ports, and individually work fine. I also tried to add eureka.client.service-url.defaultZone=http://company-service-discovery:8761/eureka
to see if it would register itself, and it worked.
我的配置服务器无法成功注册到eureka服务器,我已经对其进行了谷歌搜索,但没有发现有什么能帮助我解决这个问题.
My config server cannot successfully register to the eureka server, and I've googled it and nothing I've seen helped me solve this.
根据docker-compose文档,位于 https://docs.docker.com/compose/networking /:
According to docker-compose documentation at https://docs.docker.com/compose/networking/ :
默认情况下,Compose为您的应用设置一个网络.服务的每个容器都加入默认网络,并且都可以被该网络上的其他容器访问,并且可以在与容器名称相同的主机名下被它们发现.
By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.
在下面的示例中,web
应该能够使用postgres://db:5432
与数据库进行通信.
With the following example web
should be able to use postgres://db:5432
to communicate with the database.
version: "3"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
ports:
- "8001:5432"
我使用相同的方法来配置我的服务,但是我的配置服务器在尝试注册时被拒绝连接:
I have used the same method to configure my services, but my config server gets connection refused when trying to register:
version: '3.3'
services:
company-service-discovery:
build: company-service-discovery/
ports:
- "8761:8761"
company-config-server:
build: company-config-server/
ports:
- "8888:8888"
links:
- company-service-discovery
配置服务器bootstrap.yml
server:
port: 8888
management:
security:
enabled: false
spring:
application:
name: company-config-server
cloud:
config:
server:
native:
search-locations: classpath:/shared
profiles:
include: native
eureka:
client:
service-url:
defaultZone: http://company-service-discovery:8761/eureka
eureka服务器bootstrap.yml
spring:
application:
name: company-service-discovery
server:
port: 8761
management:
security:
enabled: false
例外
2017-07-26 14:25:05.738 WARN 1 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
2017-07-26 14:25:05.739 WARN 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_COMPANY-CONFIG-SERVER/365d20275ab0:company-config-server:8888 - registration failed Cannot execute request on any known server
问题
我的配置有问题吗?我该如何运作?
question
Is there anything wrong with my configuration ? How can I make it work ?
让我知道是否缺少任何信息,我会很乐意提供所有可能的信息.
Let me know if there's any info missing, I'll gladly give any info I can.
推荐答案
也将defaultZone
配置添加到Eureka服务器的属性中(并在 配置服务器中将service-url
更改为serviceUrl
bootstrap.yml ).
Add the defaultZone
configuration to the Eureka server's properties too (and change the service-url
to serviceUrl
in your config server bootstrap.yml).
spring:
application:
name: company-service-discovery
eureka:
client:
serviceUrl:
defaultZone: http://company-service-discovery:8761/eureka
server:
port: 8761
management:
security:
enabled: false
这篇关于Spring Cloud Netflix和Docker Compose-无法向eureka注册服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!