Docker Swarm and Private IP

When I run the application via docker, I can publish the application on the port with the IP specified.

Suppose my server has two ip (private 192.168.0.2 and public 200.168.0.2), I can open the application on the private ip with this command:

  docker run -it -p 192.168.0.2:80:80 nginx 

      

How can I achieve something like this with docker?

I guess I have to create a docker network layer first, but I don't understand what the correct syntax is.

Basically, I would like to do something like this:

    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 IP addresses of the swarm cluster servers.

+3


source to share


1 answer


Swarm does not provide the ability to listen on a specific interface, by default it listens on all interfaces. This is an open issue . Changing the overlay networks inside docker will not change this behavior.



+4


source







All Articles