0

I have angular app and java backend app running on two different docker containers in a virtual machine on production.

Angular app running on 80 (Exposed to outside world)

Backend app running on 8080 (Not exposed to outside world)

So the angular app is getting data from api's in backend which is running under 8080. Since that port is not exposed, it is unable to access to those api's. But both the apps are running in the same host.

We don't want to expose 8080 to outside, but the angular must be able to access the api's even when I access it from anywhere. Is that possible?

Thanks in advance.

Mahesh
  • 91
  • 1
  • 2
  • 9
  • Questions seeking debugging help (**"why isn't this code working?"**) must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it **in the question itself**. Questions without a **clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). Can you please [edit](https://stackoverflow.com/posts/54822795/edit) accordingly? – tgogos Feb 22 '19 at 08:23
  • 1
    @tgogos I just edited the question. Hope this helps you now. – Mahesh Feb 22 '19 at 08:41
  • Unless in different networks, containers can talk to each other without having ports exposed. – Mike Doe Feb 22 '19 at 08:46
  • @emix The virtual machine is in Google Compute Engine and I am accessing the app from my local PC. – Mahesh Feb 22 '19 at 08:50
  • 1
    It would help if you posted some actual code / commands. Also make sure you understand the difference between [`expose` and `publish`](https://stackoverflow.com/questions/22111060/what-is-the-difference-between-expose-and-publish-in-docker/) regarding your ports. Another common issue, is that if you use the `default` network (`172.17.0.0`), containers cannot communicate by using their names. – tgogos Feb 22 '19 at 09:27

1 Answers1

0

you have to use api gateway (or reverse proxy), so all microservices inluding angular app get accessed on a single port. During development you can configure proxy to serve as a gateway on port 4200 (assuming you use angular-cli and local dev server)

Normunds Kalnberzins
  • 1,213
  • 10
  • 20
  • My setup is like this: Eureka Service-Registry running on 8180 Zuul proxy running on 8080 Backend API running on random ports Angular app which is already built running on 80 with nginx – Mahesh Feb 22 '19 at 08:47
  • you need another path on nginx on port 80 say /api that forwards to port 8080, and call your apis on /api path – Normunds Kalnberzins Feb 22 '19 at 09:02