When I launch an app via docker I can publish the app on a port specifying the 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
How can I achieve something similar with docker swarm?
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
Where 192.168.0.2 and 192.167.0.1 are the IPs of the swarm cluster servers.
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.