spring boot app actually running on port 0, instead of random
It doesn't actually start it on port 0, it starts it on a random port. In your eureka server you will see that it is in port 0 but if you put yourself on top without clicking you will see in the browser bar that the port is different.
In the log it shows:
INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 0 (http)
but later changes it:
INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 64039 (http) with context path ''
INFO o.s.c.n.e.s.EurekaAutoServiceRegistration - Updating port to 64039
So if you have problems communicating with each other, it is because in every microservice you start with random port would have to configure in your application.yml
a preferIpAddress
to find it by ip and not by hostname:
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:portServer/eureka/
instance:
preferIpAddress: true
Try to set port programmatically:
@Configuration
public class ServletConfig {
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
return (container -> {
container.setPort(new Random().nextInt(65_535) + 1_000);
});
}
}
Also, this might help: Eureka not able to find port when running microservices on random port