Aleksandar Zoric
Aleksandar Zoric

Reputation: 1483

Can a Docker localhost and React Native Metro server both running on different ports communicate?

Hopefully somebody can clarify this for me;

I have an API running in a Docker container with a binded port on 8081. I then have my React Native metro server/app running on port 8899.

I want to call the API running on localhost:8081 in my React Native app.
To do so, do I need to do anything to make sure the two can communicate? i.e. port forwarding etc.

Example

.fetch('GET', 'http://localhost:8081/get_something', {
    accept: 'application/x-wifi-config',
    'content-Type': 'application/xml',
  })

Upvotes: 1

Views: 614

Answers (2)

Vijo Cherian
Vijo Cherian

Reputation: 26

You can start docker by exposing that port to host with command line option "-p 8081:8081" to "docker run" command.

Upvotes: 1

Cristian Riță
Cristian Riță

Reputation: 559

If the example doesn't work, try to change the localhost with your actual IP.

Upvotes: 0

Related Questions