Cannot fetch from preact node docker

I am running preact in a Node Docker, and a rest-api in a phpapache docker.

  • docker run --network vumc-network -p 80:80 --name phpapache phpapache
  • docker run -p 4200:4200 --network vumc-network --name node node
    When i log in the node docker I can execute:
const http = require('http');

http.get('http://phpapache/nl/menu', (res) => {
  let data = '';
  res.on('data', (chunk) => {
    data += chunk;
  });
  res.on('end', () => {
    console.log(data);
  });
}).on('error', (error) => {
  console.error(error);
});

which correctly returns a json.
But in de react-app is a function that does something similar:

fetch('http://phpapache/nl/menu')
      .then(res => res.json())
      .catch(error => {
        console.error(
          "There was a problem loading the database from DatabasesNav",
          error
        );
      });

which fails with an error: TypeError: Failed to fetch

The react app usually runs in a browser and the browser is not connected to the Docker network and can not lookup the target service IP by name.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.