spring eureka + spring gateway cloud error when executed in docker

Published

I have a simple project, a spring cloud gateway, an eureka naming service and a microservice.

when I launch the applications on my pc (not in the container) I don’t have problems, but if I launch the same with docker compose, when I execute a rest api I obtain the following error:

io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: myservice:<ip>:8002

my application.properties files are:

gateway:

spring.application.name=gateway
server.port=${GATEWAY_PORT}
eureka.client.serviceUrl.defaultZone=http://${EUREKA_URL}:${EUREKA_PORT}/eureka
spring.sleuth.sampler.probability=1.0
spring.cloud.gateway.discovery.locator.lower-case-service-id=true
spring.cloud.discovery.enabled=true
spring.cloud.gateway.discovery.locator.enabled= true 
eureka.instance.hostname=${EUREKA_URL}

eureka:

spring.application.name=eureka
server.port=${EUREKA_PORT}
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.default-zone=http://${EUREKA_URL}:${EUREKA_PORT}/eureka

service1:

spring.application.name=service1
eureka.client.serviceUrl.defaultZone=http://${EUREKA_URL}:${EUREKA_PORT}/eureka
spring.sleuth.sampler.probability=1.0
eureka.instance.hostname=${EUREKA_URL}

EUREKA_URL is defined as the name of the service in the docker-compose.

My gateway configuration is:

@Bean
public RouteLocator gatewayRouter(RouteLocatorBuilder builder) {
   return builder.routes()
          .route(p -> p.path("/service1/**")
          .filters(f -> f.stripPrefix(1))
          .uri("lb://service1/"))
          .build();
   }
}

I don’t understand where is my error.
If I execute my project on my pc, using EUREKA_URL=localhost, it works.

Thanks

Source: Docker Questions

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq