Home > database >  Docker containers in different networks communication
Docker containers in different networks communication

Time:12-19

Before asking my question, I already visited this question and I didn't see any answers.

The following scenario is that I have a frontend app (Angular), isolated from API (Node) in two separate containers, in also two separated networks. Like this:

version: '3.9'

services:

  # Backend config
  backend-app:
    image: minas-app:1.0.0
    ports:
      - 3000:3000
    networks:
      - backend

  # FrontEnd config   
  frontend-app:
    image: front-minas:1.0.0
    ports:
      - 8080:80
    networks:
      - frontend

networks:
  backend:
    driver: overlay
    attachable: true
  frontend:
    driver: overlay
    attachable: true

I have my frontend in a nginx server, but when doing the calls, it request to itself instead of my API.

In a forum, they said that the problem should be fixed with: "proxy":"http://server:3000" added in the package.json

But what I really want to know, how my front can communicate with the backend to make the API calls?

Edit: Most common questions are regarding to 2 containers running on same network, in this case I have both them isolated into frontend-network and backend-network so I want to know if its real possible the communication or if its impossible

CodePudding user response:

Your Angular frontend application will not be run in the same machine where your server will be running. Basically, your frontend application will be shipped to the client browser (through Nginx, for example), and then it will need to communicate with the server (backend application) through a connection.

you will have to make your API calls using your server IP address (or domain name), and of course, you need to expose your backend application inside your server and publish it on the correct port.

  • Related