I have wildcard dns pointed to my server e.g. *.domain.com
I'd like to route each subdomain to it's own docker container. So that box1.domain.com goes to the appropriate docker container. This should work for any traffic primarily HTTP and SSH.
Or perhaps the port can be part of the subdomain e.g. 80.box1.domain.com. I will have lots of docker containers so the solution should be dynamic not hard-coded for every container.
Another solution would be to use https://github.com/jwilder/nginx-proxy.
This tool automatically forwards requests to the appropriate container (based on subdomain via the VIRTUAL_HOST container environment variable).
For instance, if you want to redirect box1.domain.com to a container, simply set the VIRTUAL_HOST container environment variable to "box1.domain.com".
Here is a detailed tutorial I wrote about it: http://blog.florianlopes.io/host-multiple-websites-on-single-host-docker.
I went with interlock to route http traffic using the nginx plugin. I settled on using a random port for each SSH connection as I couldn't get it work using the subdomain alone.
The easiest solution would be to use the Apache mod_rewrite RewriteMap method. It's very performant when used against a text file, but it can call a script if desired. There is another StackOverflow answer that covers the script variant pretty well.
If you want to avoid Apache, the good folks over at dotCloud created Hipache to do the routing for their PaaS services. They even documented the different things they tried before building their own solution. I found a reference to tsuru.io using hipache exactly for routing to docker containers, so that definitely validates it for this purpose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With