Docker Swarm和私有IP [英] Docker Swarm and private IP
问题描述
当我通过docker启动应用程序时,可以在指定IP的端口上发布该应用程序。
When I launch an app via docker I can publish the app on a port specifying the IP.
假设我的服务器有两个IP(专用192.168.0.2和公用200.168.0.2),我可以使用以下命令在专用ip上公开一个应用程序:
Suppose that my server has two ip (private 192.168.0.2 and public 200.168.0.2), I can expose an app on the private ip with this command:
docker run -it -p 192.168.0.2:80:80 nginx
如何使用docker swarm实现类似的目标?
How can I achieve something similar with docker swarm?
我想我必须首先创建一个docker网络层,但是我不知道正确的语法是什么。
I guess I must create a docker network layer first, but I don't understand what the right syntax is.
基本上我想做类似的事情:
Basically I would like to do something similar:
docker network create \
--driver overlay \
--IP 192.168.0.2 \
--IP 192.167.0.1 \
private_net
docker service create --replicas 2 \
--network private_net --name my-web nginx
其中192.168.0.2和192.167.0.1是群集集群服务器的IP。
Where 192.168.0.2 and 192.167.0.1 are the IPs of the swarm cluster servers.
推荐答案
Swarm不提供在特定接口上侦听的选项,默认为在所有接口上监听。这是未解决的问题。在docker内部修改覆盖网络不会更改此行为。
Swarm doesn't give the option to listen on a specific interface, it defaults to listen on all interfaces. This is an open issue. Modifying overlay networks inside of docker will not change this behavior.
这篇关于Docker Swarm和私有IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!