我在同一台服务器上有两个公共(public) IP 地址 eth0 和 eth0:0。
我有两个容器,我希望它们在同一个端口上监听,但不在同一个公共(public)地址上。 我的两个容器连接到 docker0
我有:
- eth0 =192.xx.xx.50
- eth0:0 =192.xx.xx.51
- 容器1 = 172.17.0.5 ---------> 192.xx.xx.50:443
- 容器2 = 172.17.0.6 ---------> 192.xx.xx.50:9443
我想要什么:
- eth0 =192.xx.xx.50
- eth0:0 =192.xx.xx.51
- 容器 1 = 172.17.0.5 ---------> 192.xx.xx.50:443
- 容器 2 = 172.17.0.6 ---------> 192.xx.xx.51:443
我应该如何继续寻找解决方案?
- 创建一个新的 docker 网络?如何分配给第二个 IP地址?
- 其他解决方案?
谢谢
最佳答案
您应该能够使用 docker run -p ip:hostPort:containerPort ...etc... 将内部容器端口映射到 hostip:port
组合
您没有在帖子中指定内部端口,但假设容器中的应用程序正在监听端口 8080,并且您希望将其公开为 192.168.100.1:80,那么您可以这样做:
docker run -p 192.168.100.1:80:8080 ...等等...
(详情请参阅https://docs.docker.com/engine/reference/run/#expose-incoming-ports)
关于Docker 两个容器两个公共(public)IP,相同的端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48233026/