Hope you are doing good, I face a problem and try to solve it for many days but failed. I have two spring boot microservice, one is called the client and the second is called the server. When I dockerize the microservices and run the server, it runs properly but when I try to run the client, it gives me an error. the error is like.
2021-12-27 11:01:45.646 WARN 1 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator : There was a problem with the instance info replicator
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112) ~[eureka-client-1.10.17.jar!/:1.10.17]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.10.17.jar!/:1.10.17]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-1.10.17.jar!/:1.10.17]
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.10.17.jar!/:1.10.17]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-1.10.17.jar!/:1.10.17]
at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:876) ~[eureka-client-1.10.17.jar!/:1.10.17]
at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:121) ~[eureka-client-1.10.17.jar!/:1.10.17]
at com.netflix.discovery.InstanceInfoReplicator$1.run(InstanceInfoReplicator.java:101) ~[eureka-client-1.10.17.jar!/:1.10.17]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:831) ~[na:na]
The Server application.yml file is;
server.port: 8761
eureka:
instance:
hostname: eurekaserver
client:
registerWithEureka: false
fetchRegistry: false
spring:
application:
name: EUREKA-SERVER
While the client application.yml file is like;
server:
port: 8080
spring:
application:
name: EUREKA-CLIENT
eureka:
instance:
hostname: eurekaclient
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
I try defaultZone: http://eurekaserver:8761/eureka
. but got the same error.
The docker file of Client is:
FROM openjdk:17-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} eurekaclient.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/eurekaclient.jar"]
Thanks in advance 🙂
3
Answers
Try the following:
The label after service-url property (which can be aliased as serviceUrl in YML) is a HashMap KEY, not a property label. So it has to be kept as a Camel Case tag in any ways!
eureka.client.service-url.defaultZone=http://[myIP@]:8787/eureka
you can’t register to eureka server by passing localhost.
what you can do, give the container name in place of localhost and create one network, and while running the images specify the network as well.
Please follow the below steps.
Let’s say your eureka images name is -> eureka-server
first, create a network using the below command :
docker create network springcloud-ms
run the eureka container and specify the network as well like below :
docker run –name eureka-container -p 8761:8761 –network springcloud-ms eureka-server
change the application.yml of eureka client as below :
server:
port: 8080
spring:
application:
name: EUREKA-CLIENT
eureka:
instance:
hostname: eurekaclient
client:
serviceUrl:
defaultZone: http://eureka-container:8761/eureka
then run the client image. Let’s say your client image name is client-service then use the below command:
docker run –name client-container -p 8080:8080 –network springcloud-ms client-service
I don’t know if it’s still an issue for anybody but in my case (docker containers), I had to take care of the serviceUrl in the client’s application.properties. As @Qkhattak mentioned above, watch out for camel-case defaultZone!
Previously I was using (Not working):
Now using (Works perfectly):