1

With the new exciting Docker Swarm in 1.12 it seems quite possible to deploy multiple applications in a cluster of servers.

I'm looking for a way to deploy two separate applications or application entrypoints on the same port and same cluster. Consider the following:

    web.myservice.com:80 -> Swarm ->     Service[web] -> web.1
                                                      -> web.2
                                                      -> web.3

backend.myservice.com:80 -> Swarm -> Service[backend] -> backend.1
                                                      -> backend.2
                                                      -> backend.3

Where the swarm in this case in only one cluster of multiple hosts, exposing port 80. I suppose you could expose different ports and have load balancers set up to proxy_pass to this other port, but I would say it would be great to have a possibility to just expose hostname:port in the cluster, so if a request comes in on a hostname and port it will be forwarded. If you need multiple hosts or port you can expose several.

This might be available, and this is why I ask this question. Maybe it can be replicated with some advanced config of a HAProxy or Nginx. I have experimented quite some, and found it quite hard to make this extensible. Please advice on the topic if you have any comments or suggestions!

-- Marcus

Oldek
  • 2,679
  • 5
  • 23
  • 25

1 Answers1

1

When you publish a port, it binds to the node's network interface. You might be able to pull this off by using placement constraints to ensure tasks from both services are never on the same node, but I think it's best to have an nginx service to proxy the traffic for you.

Swarm makes DNS entries for your services so you can reach them easily by name, a simple nginx example would be:

http {
...
  server {
    server_name web.myservice.com;

    location / {
      proxy_pass http://web:8080;
      proxy_redirect default;
    }
  }

  server {
    server_name backend.myservice.com;

    location / {
      proxy_pass http://backend:8080;
      proxy_redirect default;
    }
  }
}
omercnet
  • 737
  • 5
  • 16