一直在考虑使用Docker进行REST服务项目.我有一个问题是我们是否可以使用Docker在同一主机/端口上运行多个版本的服务.
例如,我想在{myserver}:8080/v1 /和另一个{myserver}:8080/v2 /.
如果它完全相关,那么这些将是基于Java:8的Docker镜像,在Spring Boot REST框架上使用java jar构建.
Docker容器可以实现吗?
这是关于tcp端口作为docker工作方式的方式的问题.与两个应用程序无法绑定到同一个tcp端口的方式相同,两个docker容器也不能.
正如@Sergei Rodionov所指出的,SO_REUSEPORT可用于允许多个进程共享相同的tcp端口(这可以在启动java应用程序时指定).我认为这不会适用于容器.
是的,只要您为正在侦听的每个重复端口使用不同的网络地址,就可以这样做.
例如,您的主机分配了以下IP:192.168.11.223 10.88.88.12
您可以使用两个单独的容器来监听:192.168.11.223:80 10.88.88.12:80
如果你看一下docker run的语法:
-p=[] : Publish a container?s port or a range of ports to the host
format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
Both hostPort and containerPort can be specified as a range of ports.
When specifying ranges for both, the number of container ports in the range must match the number of host ports in the range. (e.g., `-p 1234-1236:1234-1236/tcp`)
(use 'docker port' to see the actual mapping)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13904 次 |
最近记录: |