当我在 docker 容器中部署 zuul-gateway-service 并对其进行测试时,我收到“ There was an unexpected error (type=Internal Server Error, status=500) GENERAL ”错误。但是在 Windows 中,当我在 Eclipse 中运行应用程序时,一切正常,我可以通过 zuul 网关端口访问服务,我还可以通过网关使用邮递员的每个映射。但它在 docker 容器中不起作用。
ZuulGatewayServerApplication.java ;
@EnableEurekaClient
@EnableZuulProxy
@SpringBootApplication
@EnableDiscoveryClient
public class ZuulGatewayServerApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulGatewayServerApplication.class, args);
}
}
zuul-gateway-service 的 application.properties 文件;
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
我还尝试在 zuul-gateway-service 的 application.properties 文件中添加这些代码;
eureka.client.registerWithEureka = true
eureka.client.register-with-eureka=true
ribbon.eureka.enabled=true
zuul.routes.${service_name}.strip-prefix=false
在docker中,对于zuul-gateway-service,我的Dockerfile是这样的
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"]
这就是我启动 docker 图像的方式
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
8052 端口按预期工作。
这就是我的 docker 容器进程的外观(docker ps):这里
我还尝试将 zuul-gateway-service 与其他容器链接--link。但它没有用。
相同的代码在 Windows 中运行良好,但在 docker 容器中运行良好。我希望将网关与 docker 容器中的服务连接起来。感谢您的任何点击。