Can’t really figure out why the frontend can talk to the webapp on localhost:8080, while the webapp…
Christos Petsos
2

Hi Christos Petsos, I totally understand the confusion, let’s give it a try to be more detailed:

Your computer has 3 containers running:

  • SA-Frontend exposed in port 80
  • SA-WebApp exposed in port 8080
  • SA-Logic exposed in port 5050.

You can access all of these three from your computer because you are mapping your port to that of the containers. (i.e. whatever requests you get on port localhost:80 you forward to the SA-Frontend container).

And when you send a request from SA-WebApp app being run in a container that has it’s own network (it’s own localhost) and there is nothing running on port 5050.

What makes it so confusing and you even started with it as a question “Why can Frontend talk to the WebApp?”. Let’s see how localhost resolves in this case:
The container with the frontend gives back an HTML file and the resources required by the HTML file (js/png etc.). After returning those resources everything is handled by the client (i.e. the browser) so the fetch('http://localhost:8080/sentiment') is resolved by the host where the browser is run, i.e. your computer, not the frontend container.

And as we said in the beginning you mapped your port to forward the requests to the ports in the containers.