[英]Eureka client in docker not connecting with Eureka server
I have one eureka server.我有一台尤里卡服务器。
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
I have one eureka client.我有一个尤里卡客户。
spring:
application:
name: mysearch
server:
port: 8020
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
instance:
preferIpAddress: true
My eureka client is running in a docker container.我的尤里卡客户端在 docker 容器中运行。
FROM java:8
COPY ./mysearch.jar /var/tmp/app.jar
EXPOSE 8180
CMD ["java","-jar","/var/tmp/app.jar"]
I am starting the eureka server by java -jar eureka-server.jar
After that I am starting the docker instance of the eureka client using sudo docker build -t web .
我通过
java -jar eureka-server.jar
启动 eureka 服务器之后,我使用sudo docker build -t web .
启动 eureka 客户端的 docker 实例sudo docker build -t web .
and sudo docker run -p 8180:8020 -it web
.和
sudo docker run -p 8180:8020 -it web
。 I am able to access the eureka client and server from browser but the client is not connecting with Eureka server.我可以从浏览器访问尤里卡客户端和服务器,但客户端没有连接尤里卡服务器。 I am not able to see the client in the eureka server dashboard.
我无法在尤里卡服务器仪表板中看到客户端。 I am getting below errors and warnings.
我收到以下错误和警告。
WARN 1 --- [tbeatExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
ERROR 1 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_FLIGHTSEARCH/98b0d95fd668:flightsearch:8020 - was unable to send heartbeat!
INFO 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_FLIGHTSEARCH/98b0d95fd668:flightsearch:8020: registering service...
ERROR 1 --- [nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error
WARN 1 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
WARN 1 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_FLIGHTSEARCH/98b0d95fd668:flightsearch:8020 - registration failed Cannot execute request on any known server
WARN 1 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator : There was a problem with the instance info replicator
I am doing it in an AWS EC2 Ubuntu instance.我在 AWS EC2 Ubuntu 实例中执行此操作。 Can anyone please tell me what I am doing wrong here?
谁能告诉我我在这里做错了什么?
server:
ports:
- "8761:8761"
eureka:
client:
registerWithEureka: false
fetchRegistry: false
with the above changes port 8761 will expose on host and can connect to server.通过上述更改,端口 8761 将在主机上公开并可以连接到服务器。 as your connecting using localhost " http://localhost:8761/eureka " which is searching for port 8761 on host.
作为您使用 localhost “ http://localhost:8761/eureka ”的连接,它正在主机上搜索端口 8761。
In Eureka client config use host ip instead of localhost , because if localhost used it's search for port 8761 within container在 Eureka 客户端配置中使用主机 ip 而不是 localhost ,因为如果使用 localhost 它将在容器内搜索端口 8761
Make sure you are running in Swarm mode.(Single node can also run Swarm)确保你在 Swarm 模式下运行。(单节点也可以运行 Swarm)
$ docker swarm init
An overlay network is created so services can ping each other.创建了一个覆盖网络,以便服务可以相互 ping。
$ docker network create -d overlay mybridge
Set application.property for eurika client as below为 eurika 客户端设置 application.property 如下
eureka.client.service-url.defaultZone=http://discovery:8761/eureka
Now create first discovery service (Eureka discover server)现在创建第一个发现服务(Eureka 发现服务器)
$ docker service create -d --name discovery --network mybridge \
--replicas 1 -p 8761:8761 server-discovery
Open your browser and hit any node with port 8761打开浏览器并点击任何端口为 8761 的节点
Now create client service:现在创建客户端服务:
$ docker service create -d --name goodbyeapp --network mybridge \
--replicas 1 -p 2222:2222 goodbye-service
This will register to the discovery service.这将注册到发现服务。
In the container world, the eureka server ip address can change each time the eureka server is restarted.在容器世界中,eureka服务器每次重启时eureka服务器ip地址都可以改变。 Hence specifying the host ip address for eureka server url doesn't work all the time.
因此,为 eureka 服务器 url 指定主机 ip 地址并不总是有效。
In the docker-compose.yml, I had to link the eureka client service to the eureka server container.在 docker-compose.yml 中,我必须将 eureka 客户端服务链接到 eureka 服务器容器。 Until I link the services, eureka client couldn't connect to the server.
在我链接服务之前,尤里卡客户端无法连接到服务器。
This is already answered in another post recently: Applications not registering to eureka when using docker-compose最近在另一篇文章中已经回答了这个问题: Applications not registering to eureka when using docker-compose
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.