docker容器内的多个spring boot

时间:2018-09-27 08:36:10

标签: docker spring-boot

我们正在使用docker和spring boot,这是相当新的..

这是我们的用例:

* There are three Spring Boot based web applications 
  - web1 = works on port 8010 = exposes API as http://...:8010/web1/rest/someEndPoint_1
  - web2 = works on port 8020 = exposes API as http://...:8020/web2/rest/someEndPoint_2 
  - web3 = works on port 8030 = exposes API as http://...:8030/web3/rest/someEndPoint_3

* All of these should be packaged in single docker image 
* Docker may have apache/haproxy/nginx and it should expose port 8080, which 

将映射到8080处的主机端口

* Here is requirement : 

  - If request will come to Docker as http://DOCKER_HOST_IP:8080/web1/rest/someEndPoint_1 
        ==> host will forward traffic to container 
        ==> Proxy running inside container will see pattern 
        ==> http://...:8010/web1/rest/someEndPoint_1

  - If request will come to Docker as http://DOCKER_HOST_IP:8080/web2/rest/someEndPoint_1 
        ==> host will forward traffic to container 
        ==> Proxy running inside container will see pattern 
        ==> http://...:8020/web2/rest/someEndPoint_1

  - If request will come to Docker as http://DOCKER_HOST_IP:8080/web3/rest/someEndPoint_1 
        ==> host will forward traffic to container 
        ==> Proxy running inside container will see pattern 
        ==> http://...:8030/web3/rest/someEndPoint_1

有可能实现吗? (基本上,我们被要求检查是否可以根据URL模式路由流量?)

请随时添加评论/编辑问题! 谢谢,提前。 问候。

1 个答案:

答案 0 :(得分:2)

您正在寻找API网关,它将网关将传入的请求路由到另一服务点。您应该查看Spring Cloud Gateway,看看它是否可以满足您的需求。

配置应该非常简单,您将在8080端口上公开网关,并配置到所有服务的正确路由。

之后,您将能够将所有API汇总到一个ip:port

更多信息可以在cloud gateway tutorial上找到。