Search code examples
javascriptnode.jsrubydockerlocal

Failed to open TCP connection to localhost:3002


I'm running a ruby server on docker, that tries to call a node API running on a different port. ruby - 3000 node - 3002 I'm trying to call locally to this URL (to the ruby app to my node API) :

auth_response = RestClient.post("http://localhost:3002/login", body, header)

then I get this error :

**"#<Errno::EADDRNOTAVAIL: Failed to open TCP connection to localhost:3002 (Cannot assign requested address - connect(2) for "localhost" port 3002)>"**

i tried calling to my node API from postman to the exact URL below and i succeeded, i also tried to add this to the running API :

server.listen(3001,"127.0.0.1");

and it didn't work for me, still got this error, is it related to docker? is it because it's locally? please share any knowledge about it if you have any idea


Solution

  • The problem was that my ruby project runs on docker and the API does not, I managed to solve it temporarily and succeeded to get a response from the API, by changing the URL in ruby to "host.docker.internal:3002/login" for example. right now I need to configure it in the docker to work locally.