Docker Community Forums

Share and learn in the Docker community.

How to access multiple docker-compose instances with different domains on same machine


(Yannisc) #1

What is the best way to be able to run multiple docker compose instances on the same machine and be able to access multiple ports (e.g. 80 for web, 8983 for solr) on the same machine with different domain each?


(Nathan Le Claire) #2

You could easily forward the same ports from the containers to arbitrary high ports on the host’s localhost by using Docker Compose’s ports: key (https://docs.docker.com/compose/compose-file/#/ports). If you want custom DNS resolution to containers then you need to run your own DNS server and indicate that your host should point to it. If you are running Docker on Linux natively this might be do-able by resolving to the Docker bridge network IPs, but on Mac or Windows it involves additional pain of somehow connecting to the container in the VM directly. I’d just use high ports unless you want DNS entries very badly, in which case you need to put in the elbow grease to rig up dnsmasq etc.


(Yannisc) #3

Thank you for your answer!

I think this is doable.

How about using some kind of proxy that would find the open ports and match the domains? Like jwilder nginx proxy for docker? Is there a similar solution for docker-compose?


(Nathan Le Claire) #4

You could do that (and in fact it would likely be required on something like OSX where you could direct requests to that proxy, and forward to the appropriate vhost/container) but the tricky part will always be exposing and using your custom DNS server from wherever you want app.docker (or whatever) to resolve to. You will need to set up software so that your host knows how to resolve requests that you make which are intended to land on containers.


(Yannisc) #5

I wish there were a ready-made solution to this…


(Nathan Le Claire) #6

There is dinghy available to at least take a look at. However I need to be clear that it is not an official Docker, Inc. solution, nor is it endorsed by Docker, Inc. I’m sure the Docker for Mac / Docker for Windows team are interested in potentially exploring functionality such as this some day. cc @avsm @dgageot @jeanlaurent


(Nathan Le Claire) #7

Oh cool, dinghy DNS / http proxy is available as a completely separate piece as well: https://github.com/codekitchen/dinghy-http-proxy Nice one @codekitchen!