I would like to start 4 different containers using swarm mode. They may be of the same or different images but will run in the same docker network. Let us say they are myapp1, myapp2…4.
I would like to put them behind a reverse proxy such that if someone access http://m1, the reverse proxy will take the traffic to myapp1, m2 will go to myapp2 and so on.
The intention is to hide the IP addresses of myapp1-4 from external users, while allowing name-based routing to reach them.
I know that swarm mode does load balancing. But here I am looking for DNS-like features. Does swarm mode have such features?
Swarm mode DNS allows you to do container <=> container communication based on service name, e.g., curl foo in a service on the same network as a docker service with --name foo will hit the VIP for all task instances in that service (i.e., it will load balance among all containers in the service using DNS entry foo). This is all inside the container(s).
My advice would be to put them in separate services on the same network and have a simple L7 rev proxy (nginx, haproxy, caddy) that routes the actual hostname from outside world to these internal hosts. Or, you could even configure it so that there’s a rule automatically forwarding, e.g., myhost.com/(.*) to the relevant service and then you wouldn’t need to update the config to add a new one, just run it.