0

I have a setup similar to the following pseudo docker-compose.yml

services:   
  app:
    build: ./app   
  message-broker:
    build: ./message-broker

app is a node.js app, and I return an html file that makes a GET request to the message-broker service. So my question is:

How do I pass the hostname/IP address of the message-broker service to the front-end so that I can make a request from the node app?

adebasi
  • 3,535
  • 2
  • 19
  • 33
johnklawlor
  • 1,708
  • 2
  • 13
  • 15
  • 1
    You can make the request to the node app and proxy the request to the message-broker. Take a look at this post: https://stackoverflow.com/questions/10435407/proxy-with-express-js – adebasi Apr 02 '18 at 16:11
  • Did you get an answer to this question? The answer below might work ok for an internal service, but I don't think works well for using from a webpage. – cs94njw Aug 23 '18 at 16:37
  • I followed @adebasi's suggestion. You want your server (e.g. node.js, nginx, apache, etc.) to proxy a request from your front-end to the message broker. Your web page knows how to communicate with your server, and your server knows how to resolve and proxy to every other containerized service. – johnklawlor Aug 23 '18 at 17:53

1 Answers1

0

Add a depends_on section to your app service:

services:   
  app:
    build: ./app 
    depends_on:
    - message-broker

And then you can make requests to the message-broker service by using http://message-broker:<port>.

Docs: https://docs.docker.com/compose/compose-file/#depends_on

Yuankun
  • 6,875
  • 3
  • 32
  • 34