This question already has answers here:
From inside of a Docker container, how do I connect to the localhost of the machine?
(40 answers)
Closed 2 years ago.
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.
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.
Related
I'm getting connection refused whenever I try to migrate on rails. Running rails db:migrate gives:
Failed to open TCP connection to 127.0.0.1:8126 (Connection refused - connect(2) for "127.0.0.1" port 8126)
I tried checking if something is already taking up this port using:
netstat -vanp tcp | grep 8126
but there is nothing.
For extra measure, I made sure that docker is not running. Nothing seems to fix the issue though. Not sure what other info to include or what other thing can I try.
Any hints would be greatly appreciated
I worked on my computer (mac os High Sierra 10.13.4) for a Rails application. I had Postgres, Redis and ElasticSearch installed via Homebrew.
I recently started to dockerize the app on a new branch.
When I went back to my main branch, none of the brew services were working:
PG::ConnectionBad - could not connect to server: Connection refused
which I fixed thanks to https://dba.stackexchange.com/questions/75214/postgresql-not-running-on-mac
couldn't connect to redis
which I fixed by running redis-cli
Errno::ECONNREFUSED - Failed to open TCP connection to localhost:9200 (Connection refused - connect(2) for "::1" port 9200)
I tried stopping/starting, desinstalling/reinstalling elasticsearch and even desinstalling/reinstalling Homebrew. I'm considerating doing a clean reinstall of my computer.
I don't understand how working on docker could break services on my computer, I thought it was supposed to fix exactly that kind of problems.
Any help on getting elasticsearch to work would be really appreciated!
This answer is only a speculation. A little more information might help us figure out what’s really going on here.
Are the Docker containers still running?
If yes, do they use the same ports that these services do on your Mac?
If the answer to both the above questions was yes, then you’ve found your problem.
What I mean to say is that if the containers are running and one of them is mapped to the port 9200, which also happens to be the port on which the required services on your Mac listen to by default, then these services cannot run on that port as it is already being used by one of your containers.
Solution: If this is the case, stop the containers and try running your services again
I am using capistrano 2.15.5 for my rails application deployment. I am using localhost for server and have also tried with 127.0.0.1 in place of localhost. After running *cap production deploy:setup* the error that i am getting is: **Errno::ECONNREFUSED: Connection refused - connect(2)**.
After searching for it i found out ECONNREFUSED means the client couldn't make a TCP connection to the server, either because it's down, or its DNS is not resolving..
how to fix this issue?
thanks.
You have to add your ssh key in server's ssh authorize keys
Hi I'm receiving an SSL issue on my rails app on my local server:
An error occurred during a connection to localhost:3000.
SSL received a record that exceeded the maximum permissible length.
(Error code: ssl_error_rx_record_too_long)
and was told that opening port 443 would fix the problem. I've looked around everywhere but there doesn't seem to be an answer. Could someone go through the process of how I would open port 443?
So, someone is advising you to open that port in your firewall. I don't think this will help, since you're connecting to port 3000, but it might be that you're running a proxy on port 3000 that needs to connect to port 443.
Instead of opening that port I would suggest disabling your firewall and retrying that. If it works, then you should look into making an exception for that port. Here's how to disable the firewall: (Which will open that port)
Open System Preferences->Security->Firewall and click "Stop". Don't forget to turn it back on when you're done testing.
I have one server called 'testapp' and client machine called 'clientapp'.I am trying to install one windowservice called 'SVM' on client machine. If install 'SVM' in 'clientapp' and configure 'testapp' as Server here in this service tab, Then in server 'testapp' i can see client machine as connected and server will start monitoring.
But what actually going is i am not able to install windowservice on client. I am getting error which is mentioned down as trace file:
Actively refused it means that the machine was reachable but it replied with a nack.
This means that nothing is listening on that port for that IP address.
You have to assure that your server is listening and that he is listening for connections on your localhost.
It could probably help too if you just used 127.0.0.1 as local host. Whatever you put after 127. will connect you with your local host, but 127.0.0.1 is used by convention.
127.xx.xx.xx is reserved for loopback to the same machine - in other words, that's not actually trying to talk to the server. It's unclear where that address has come from, but if you find the right address, it may just start to work.