[英]EurekaServer com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server on Docker
Eureka server not working on Docker compose Eureka 服务器无法在 Docker 上运行
Here is the docker-compose for the Eureka server and config server这是 Eureka 服务器和配置服务器的 docker-compose
version: '3'
services:
fetebird-eurekaservice:
container_name: FeteBird-EurekaService
build:
context: ../../Eureka-Service-Registry/
dockerfile: Dockerfile
image: fetebird/eurekaservice
ports:
- "8761:8761"
networks:
- spring-cloud-network
volumes:
- ./fetebird-eurekaservice/data:/data
logging:
driver: json-file
fetebird-configserver:
container_name: FeteBird-ConfigServer
build:
context: ../../FeteBird-ConfigServer
dockerfile: Dockerfile
image: fetebird/configserver
ports:
- "8085:8085"
networks:
- spring-cloud-network
volumes:
- ./fetebird-configserver/data:/data
logging:
driver: json-file
networks:
spring-cloud-network:
driver: bridge
I tried with the expose command as well but no luck我也尝试过使用expose命令,但没有运气
FROM openjdk:14
WORKDIR /fetebird-eurekaservice/service
ADD build/libs/fete-bird-eureka-service-registry-0.0.1-SNAPSHOT.jar fete-bird-eureka-service-registry-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar", "fete-bird-eureka-service-registry-0.0.1-SNAPSHOT.jar"]
FROM openjdk:14
WORKDIR /fetebird-eurekaservice/service
ADD build/libs/fete-bird-configuration-server-0.0.1-SNAPSHOT.jar fete-bird-configuration-server-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar", "fete-bird-configuration-server-0.0.1-SNAPSHOT.jar"]
@SpringBootApplication
@EnableEurekaServer
public class FeteBirdEurekaServiceRegistryApplication {
public static void main(String[] args) {
SpringApplication.run(FeteBirdEurekaServiceRegistryApplication.class, args);
}
}
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
spring:
profiles:
active: dev
spring:
application:
name: CONFIG-SERVER
profiles:
active: native
cloud:
config:
server:
native:
search-locations: classpath:/config
server: port: 8085服务器:端口:8085
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka/
instance:
hostname: localhost
Errors错误
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
FeteBird-ConfigServer | at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer | at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer | at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:857) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer | at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:121) ~[eureka-client-1.9.21.jar!/:1.9.21]
FeteBird-ConfigServer | at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
FeteBird-ConfigServer | at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
FeteBird-ConfigServer | at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
FeteBird-ConfigServer | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
FeteBird-ConfigServer | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
FeteBird-ConfigServer | at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
FeteBird-ConfigServer |
FeteBird-ConfigServer | 2020-07-20 14:30:19.268 WARN 1 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator : There was a problem with the instance info replicator
The problem is this问题是这个
eureka:
client:
serviceUrl:
defaultZone: http://localhost:1111/eureka
It is pointing to localhost and Eureka is no longer running on localhost, localhost in this case is the individual containers.它指向 localhost 并且 Eureka 不再在 localhost 上运行,在这种情况下 localhost 是单个容器。 The containers are linked together so you can just change this to
容器链接在一起,因此您可以将其更改为
eureka:
client:
serviceUrl:
defaultZone: http://fetebird-eurekaservice:8761/eureka/
instance:
hostname: fetebird-eurekaservice
Each docker file每个 docker 文件
ENTRYPOINT ["java", "-jar", "fete-bird-configuration-server-0.0.1-SNAPSHOT.jar"] fetebird-eurekaservice
Docker compose file (Add links and depends_on) Docker 撰写文件(添加链接和depends_on)
fetebird-configserver:
container_name: FeteBird-ConfigServer
build:
context: ../../FeteBird-ConfigServer
dockerfile: Dockerfile
image: fetebird/configserver
ports:
- "8085:8085"
links:
- fetebird-eurekaservice
depends_on:
- fetebird-eurekaservice
networks:
- spring-cloud-network
volumes:
- ./fetebird-configserver/data:/data
logging:
driver: json-file
Reference - https://github.com/spring-cloud/spring-cloud-netflix/issues/2442参考 - https://github.com/spring-cloud/spring-cloud-netflix/issues/2442
As pointed out by OP's answer: Eureka is no longer running on localhost, localhost in this case is the individual containers.正如 OP 的回答所指出的:Eureka 不再在 localhost 上运行,在这种情况下,localhost 是各个容器。
I'm here to introduce two addtional solutions:我在这里介绍两个额外的解决方案:
Dev environment (in application.properties):开发环境(在 application.properties 中):
eureka.client.service-url.defaultZone = http://localhost:8761/eureka
Docker environment (override defaultZone settings in docker-compose.yml
file): Docker 环境(覆盖
docker-compose.yml
文件中的 defaultZone 设置):
myservice:
container_name: myservice
environment:
eureka.client.service-url.defaultZone: http://<your-eureka-service-name>:8761/eureka
This will override application.properties
or application.yml
values.这将覆盖
application.properties
或application.yml
值。
If you'd like to override a bunch stuff in docker environment like jdbc connection, you can use SPRING_APPLICATION_JSON
(spring will read it as it is embedded in an environment variable or system property):如果你想覆盖 docker 环境中的一堆东西,比如 jdbc 连接,你可以使用
SPRING_APPLICATION_JSON
(spring 会读取它,因为它嵌入在环境变量或系统属性中):
myservice:
container_name: myservice
environment:
SPRING_APPLICATION_JSON: '{
"spring.datasource.url=jdbc:mysql": "//jdbc:mysql:3306/mydb",
"spring.datasource.username": "username",
"spring.datasource.password": "password",
"spring.jpa.hibernate.ddl-auto": "update",
"eureka.client.service-url.defaultZone": "http://<your-eureka-service-name>:8761/eureka"
}'
Step one, prepare two versions of application.properties
, if you prefer application.yml
, your choise:第一步,准备两个版本的
application.properties
,如果你更喜欢application.yml
,你的选择:
application-default.properties
for dev environment:开发环境的
application-default.properties
:
eureka.client.service-url.defaultZone = http://localhost:8761/eureka
application-docker.properties
for docker environment: docker 环境的
application-docker.properties
:
eureka.client.service-url.defaultZone = http://<your-eureka-service-name>:8761/eureka
Step two (docker-compose file):第二步(docker-compose 文件):
myservice:
container_name: myservice
environment:
SPRING_PROFILES_ACTIVE: docker
By setting up SPRING_PROFILES_ACTIVE to docker, it will load application-docker.properties
as active profiles.通过将SPRING_PROFILES_ACTIVE设置为 docker,它将加载
application-docker.properties
作为活动配置文件。
References:参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.