Postgresql DB not getting connected in docker

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.

Upvotes: 1

Views: 897

Answers (2)

Mayur Shah
Mayur Shah

Reputation: 3449

Try this one

docker restart container-name

sudo service postgresql restart

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

Upvotes: 1

fishi0x01
fishi0x01

Reputation: 3759

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.

Upvotes: 0

Related Questions