1

My rails application is running in docker. I am having my server running and listening on host 'localhost' and port 3000. But when I hit the browser with 'http://localhost:3000/' I get the below error-

PG::ConnectionBad at /

could not connect to server: Connection timed out Is the server running on host "db" (184.168.221.24) and accepting TCP/IP connections on port 5432?

I am unable to find out from where this '184.168.221.24' IP is coming. Thanks.

3
  • Do you start your containers via compose? This looks like you have a linked db container. Containers run on a virtual network on your machine Commented Jun 27, 2017 at 10:07
  • Yes I am running 'sudo docker-compose up' for server start. Commented Jun 27, 2017 at 10:10
  • Well it looks like your db container is either not starting up properly or not allowing connnections from your app container. Can you verify that your db container is running (docker ps). And did you expose port 5432 on your db container? Commented Jun 27, 2017 at 10:14

2 Answers 2

1

Try this one

docker restart container-name

sudo service postgresql restart

This will restart your PostgreSQL, hope this will be helpful for you.

Sign up to request clarification or add additional context in comments.

14 Comments

got this postgresql: unrecognized service
try this sudo yum install postgresql-server
No he wants to run it in a compose stack. Not install it on a local machine
Hey Mayur, when I run this 'psql --version', I got this 'psql (Postgres-XC) 1.1 (based on PostgreSQL) 9.2.4'. That means postgresql-server is installed on my machine. Right?
What about restarting docker-machine restart dev or boot2docker stop boot2docker start
|
0

As I already mentioned in the comments, it looks like your db container is either not starting up properly or not allowing connections from your app container. Verify that your db container is running (docker ps). Further, ensure that you expose port 5432 on your db container to other containers in your compose stack.

4 Comments

DB container is running with image - mdillon/postgis:9.6
Then it is most likely because port 5432 is not exposed. You can use expose: 5432 in your compose yaml to open it to linked containers. Docu
This is what I am having in docker-compose.yml file- db: image: mdillon/postgis:9.6 ports: - '5433:5432'
Any other way to expose: 5432 ?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.