spring-bootdockermicroservicesnetflix-zuulproxy-server

Netflix-zuul can't route spring boot microservice api in docker


I'm getting "There was an unexpected error (type=Internal Server Error, status=500) GENERAL" error when i deploy my zuul-gateway-service in docker container and test it. But in windows, when i run applications in eclipse, everything is working just fine, i can reach services via zuul gateway port and i can also use every mapping with postman through gateway. But it doesnt work in docker containers.

ZuulGatewayServerApplication.java ;

@EnableEurekaClient
@EnableZuulProxy
@SpringBootApplication
@EnableDiscoveryClient
public class ZuulGatewayServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ZuulGatewayServerApplication.class, args);
    }
}

application.properties file for zuul-gateway-service;

server.port=8762
spring.application.name=t-zuul-server
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka

zuul.ignored-services=*

zuul.routes.t-author-bookstore.path=/author/**
zuul.routes.t-author-bookstore.service-ıd=t-author-bookstore
#zuul.routes.t-author-bookstore.strip-prefix=false

zuul.routes.t-book-bookstore.path=/book/**
zuul.routes.t-book-bookstore.service-ıd=t-book-bookstore
#zuul.routes.t-book-bookstore.strip-prefix=false
#... there is also 4 more services

I also tried to add those codes in application.properties file for zuul-gateway-service;

eureka.client.registerWithEureka = true
eureka.client.register-with-eureka=true
ribbon.eureka.enabled=true
zuul.routes.${service_name}.strip-prefix=false

In docker, for zuul-gateway-service, my Dockerfile is like this

FROM openjdk:8-alpine
VOLUME /tmp
COPY t-zuul-gateway-server-1.0.jar t-zuul-app.jar
EXPOSE 8762
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/t-zuul-app.jar"]

This is how i start docker images

docker run -d --network=bookstore-mongodb -p 8761:8761 --name t-eureka-server t-eureka-server-1.0
docker run -d --network=bookstore-mongodb -p 8762:8762 --name t-zuul-servicee --link=mongo --rm -e EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://localhost:8761/eureka t-zuul-gateway-server-1.0
docker run -d --network=bookstore-mongodb -p 8052:8052 --name t-book-bookstore --link=mongo --rm -e EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://localhost:8761/eureka t-book-bookstore-1.0

Port 8052 is working as expected.

This is how my docker container processes looks (docker ps): here

I also tried to link zuul-gateway-service with other containers --link. But it didn't work.

Same codes are working fine in windows but not in docker containers. I expect to connect the gateway with services in docker containers. Thanks for any hits.


Solution

  • All codes writen in post and others are correct except this code ;

    zuul.routes.xyz.service-ıd=xyz
    

    It should be like this ;

    zuul.routes.xyz.serviceId=xyz
    

    And also this service id must be same with spring.application.name value for every service.

    Actually i dont know why eclipse is suggesting this but the correct code is that i mentioned as second one.