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.