Search code examples
reactjsdockerdocker-network

UI cannot access Node server when launched on Docker and served over an IP


This is my situation.
Docker Containers

1. Node/Play/Any BackEnd Server
2. React
3. Other services

I have launched them using docker-compose and everything works fine. The problem is:
When I launch docker-compose on a VM and serve the UI over an IP it is not able to access the node server.

It happens since the React Code is configured to access the Node server at http://node-backend:9000(where node-backend is the name of the docker container that runs nodejs) and react sends this exact URL to the client on some other machine, which cannot resolve this address since http://node-backend:9000 is internal to Docker.

How do I solve this issue without using nginx or any other proxying service?


Solution

  • You should change your configuration of React. Never use the local container name when you want to server over the network.

    Here are the steps you need to take

    1. Port mapping for node server. You are probably doing this already.
    2. Make sure that the port 9000 on server is exposed.
    3. Configure the react app to use the IP address to connect to node server (NOT named instance).
    4. At this point, you should see the calls happening over network like http://:9000