1

I have an application running inside Docker(M1). And an another application running on localhost(M2-Not Dockerized). Both are Ruby on Rails applications running on ports 3000 and 3001. I am calling M2 from inside of M1 by using

response = http_client.post("127.0.0.1:3001", query, {}, options)

But I keep on getting

Error: Failed to open TCP connection to 127.0.0.1:3001 (Connection refused - connect(2) for "127.0.0.1" port 3001), Backtrace: ["/usr/local/lib/ruby/2.5.0/net/http.rb:939:in `rescue in block in connect'", "/usr/local/lib/ruby/2.5.0/net/http.rb:936:in `block in connect'", "/usr/local/lib/ruby/2.5.0/timeout.rb:93:in `block in timeout'", "/usr/local/lib/ruby/2.5.0/timeout.rb:103:in `timeout'", "/usr/local/lib/ruby/2.5.0/net/http.rb:935:in `connect'"

If i use -

response = http_client.post("localhost:3001", query, {}, options)

then i get

Error: Failed to open TCP connection to localhost:3001 (Cannot assign requested address - connect(2) for "localhost" port 3001), Backtrace: ["/usr/local/lib/ruby/2.5.0/net/http.rb:939:in `rescue in block in connect'", "/usr/local/lib/ruby/2.5.0/net/http.rb:936:in `block in connect'"

So it changed from Connection refused to Cannot assign requested address.

I am able to access both the applications by calling localhost:3000 and localhost:3001 from the browser individually. I am assuming it is happening because of a Dockerized application calling a Non-Dockerized one. Can someone suggest how to establish the connection between the two, I have tried many things. I am running Docker-2.1.0.5 on macOS Mojave 10.14.6 and Ruby 2.5.0. Let me know if any other information is required.

1 Answers1

0

The issue may be in your request for "localhost". In your request, replace localhost with 0.0.0.0. It will most likely work. See https://github.com/moby/moby/issues/2522 for more info. As according to muellermichel: It's basically the same when you want to make couchdb accessible from outside your host, no matter whether it runs in a container or not: you need to bind it's address to 0.0.0.0:

So just use 0.0.0.0 and you'll most likely be okay!

EDIT:

This may be an active issue, with a fix not yet available. See https://github.com/topofocus/active-orient/issues/22 for the github thread, no solutions still exist.

EDIT 2:

See Failed to open TCP connection to localhost:9200 (Cannot assign requested address - connect(2) for "localhost" port 9200). It may solve your problems.

Math Bob
  • 113
  • 1
  • 6
  • It is giving the same error `Failed to open TCP connection to 0.0.0.0:3001 (Connection refused - connect(2) for "0.0.0.0" port 3001), Backtrace: ["/usr/local/lib/ruby/2.5.0/net/http.rb:939:in `rescue in block in connect'", "/usr/local/lib/ruby/2.5.0/net/http.rb:936:in `block in connect'", "/usr/local/lib/ruby/2.5.0/timeout.rb:93:in `block in timeout'` – user11037262 Apr 30 '20 at 22:02
  • https://github.com/topofocus/active-orient/issues/22 this github issue comes up as a search result. it seems 0.0.0.0 may be the best solution, but still one that does not always work – Math Bob Apr 30 '20 at 22:05
  • yes, i have read somewhere that maybe Puma is causing issues depending on the version. Still checking out the links. – user11037262 Apr 30 '20 at 22:09
  • make sure you also change m2 from localhost to 0.0.0.0 – Math Bob Apr 30 '20 at 22:11
  • no matter whether I bind M2 to 0.0.0.0, i am able to access it from browser by calling localhost or 0.0.0.0 or 127.0.0.1. Still i'll check this thing also, maybe Dockerized application(M1) needs M2 to be explicitly bind to 0.0.0.0. – user11037262 Apr 30 '20 at 22:16