2

I have a simple node script that runs in a container and a nginx container running 2 different web-sites (let's call them default.example.com and foobar.example.com). default.example.com is configured a the default host in the nginx file.

So when I make a call to http://nginx from my node container, I will reach the default.example.com page. But how can I curl the foobar.example.com from the node container?

I think I have to pass the domains in my docker compose file so the containers know where the following request will go, but I haven't found a solution yet.

cre8
  • 13,012
  • 8
  • 37
  • 61
  • Have you tried setting the `Host` header? So: `curl -H 'Host: foobar.example.com' http://nginx`. This should even work with IP instead of "nginx"... Also, checkout [this](https://stackoverflow.com/a/39707966/3727050) for adding hostnames/aliases to a container – urban Apr 20 '18 at 08:51
  • @urban this worked. But is there also a way to tell docker where to route? In my node container I can only pass a domain to the program (so either `http://nginx` or `http://foobar.example.com` and can't modify the header. – cre8 Apr 20 '18 at 08:56
  • 1
    Check the link above. I have not tried it so not sure how it works, but it seems that network aliases allows you to add multiple FQDNs on the same container – urban Apr 20 '18 at 08:58
  • Adding aliases to the network causes a non responding curl result. – cre8 Apr 20 '18 at 09:20
  • Hmm, the only other thing I can think of is setting aliases within the container in `/etc/hosts` (`extra_hosts` in docker-compose) - details [here](https://docs.docker.com/compose/compose-file/#extra_hosts). That should be configured in the client box – urban Apr 20 '18 at 11:51
  • you could create just directive on your default nginx website like `/foobar` and host the app there rather on seperate url – Mazel Tov Apr 20 '18 at 18:13

0 Answers0