Docker Community Forums

Share and learn in the Docker community.

Different domain name and ip but same port with docker compose

Hi I would like to ask, how can i expose multiple containers from one machine with different domain names, different ip addresses but in the same port?
For example:

  • A container “asystems” which I want to response to the IP:10.3.2.20, Port:80 and DomanName: asystems.mydomain.com (this may be a nginx or apache or flask etc )
  • A container “bsystems” which I want to response to the IP:10.3.2.21, Port:80 and DomanName: bsystems.mydomain.com (this may be a nginx or apache or flask etc )
  • A container “csystems” which I want to response to the IP:10.3.2.23, Port:80 and DomanName: csystems.mydomain_com (this may be a nginx or apache or flask etc )

I would prefer a docker-compose solution if available.

Thank you

The typical approach would be to register the subdomains in your dns service and point them all of them your docker host (or a loadbalancer) and then run a preferably containerized reverse proxy (like nginx, apache or traefik) that forwards traffic depending on the subdomain to its target container.

Even though you prefer a docker-compose only solution, you should consider to create the network for the reverse proxy communication from the command line (or portainer) to decouple the networks existance from the lifecycle of a specific docker-compose stack. Then declare this network as external in the docker-compose files of the reverse proxy and those of the other services. This way port 80 (and preferable 443) need to be expose on the reverse proxy container and the traffic would be forwarded to the target containers, without exposing ports for them.

I hope this makes sense.