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("", 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

3

1 Answer

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest