-3

When I run the command on docker container backend:
psql -h localhost -p 5432 -U postgres

I receive the following error:

psql: error: connection to server at "localhost" (::1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? 

My docker-compose, dockerfile, database.yml.

I'm running my application via Docker Compose on Ubuntu 24.

6
  • 1
    Post the files as text in the question itself, and clarify where you run the psql . -h localhost command. This will work only inside the PostgreSQL container, or the host if you expose 5432 to the outside world. Inside the other containers the database will appear as a machine whose name matches the service name, eg mydb or postgres or db Commented Nov 24 at 13:15
  • 1
    This is the 3rd time you have asked a contextually similar question, the previous 2 were closed for lacking appropriate details (and subsequently it appears you have deleted them), can you please explain what distinguishes this from those? Commented Nov 24 at 15:50
  • Your docker-compose file is exposing port 5433. Your database.yml does not account for this in either the development or test settings. Commented Nov 24 at 16:41
  • I can access PostgreSQL when I run: psql -h db -p 5432 -U postgres But whent I try: rails db:create I have the following return: Is the server running locally and accepting connections on that socket? connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory Commented Nov 24 at 21:32
  • I changed the ports from 5433 to 5432 and replaced the name localhost with db, and then ran the command psql -h db -p 5432 -U postgres and it worked. But then when I run the command rails db:create I get the following error: I have the following return: Is the server running locally and accepting connections on that socket? Connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory Commented Nov 25 at 12:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.