1
votes

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.

2
you need to replace the localhost in your application.properties for zuul-gateway-service by the name of your eureka server image.sak

2 Answers

3
votes

I'm not a 100% sure, but I think it's about your Zuul can not connect to Eureka. I guess the reason is you are using localhost as the address for Eureka, but localhost is also defined within the container and points to it self instead of your host machine.

Have you tried using docker-compose? In your compose file you could do something like:

version: '3.3'
services:
    eureka:
        image: t-eureka-server-1.0
        ports:
            - "8761:8761"

    zuul:
        image: t-zuul-gateway-server-1.0
        ports:
            - "8762:8762"
        depends_on:
            - "eureka"
        links:
            - "eureka:eureka"

    bookstore:
        image: t-book-bookstore-1.0
        ports:
            - "8052:8052"
        links:
            - "eureka:eureka"

Of course you need to add your mongo DB to make it work, but you can check wether the Zuul can connect to Eureka.

-1
votes

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.