How to fix messed up postgresql docker connection

Everything was working fine, until suddenly my docker-compose up & manage.py migrate & manage.py makemigrations all started failing.

an example is below.

C:\Users\tgmjack\Desktop\londonappdevelopersexample\my_ec2_ting\app>python manage.py makemigrations
C:\Users\tgmjack\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\commands\makemigrations.py:143: RuntimeWarning: Got an error checking a consistent migration history performed for database connection ‘default’: connection to server at “localhost” (::1), port 5432 failed: Connection refused (0x0000274D/10061)
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 (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections?

warnings.warn(
No changes detected

Since the error complained of inconsistent migration history, i deleted my migrations folder thinking i could just start again. That changed nothing, so then i decided to delete all my previous containers and images in docker too.

The postgresql server is now running again after doing another docker build. but it still doesnt want to connect.

below is the last bunch of lines from the logs of my postgresql server copied from inside docker desktop. I believe this shows that im doing things right (ie my server is running on 0.0.0.0:5432)

022-10-29 08:53:48.707 UTC [1] LOG:  received fast shutdown request
2022-10-29 08:53:48.709 UTC [1] LOG:  aborting any active transactions
2022-10-29 08:53:48.710 UTC [1] LOG:  background worker "logical replication launcher" (PID 56) exited with exit code 1
2022-10-29 08:53:48.710 UTC [51] LOG:  shutting down
2022-10-29 08:53:48.727 UTC [1] LOG:  database system is shut down
2022-10-29 09:21:51.481 UTC [1] LOG:  starting PostgreSQL 13.8 on x86_64-pc-linux-musl, compiled by gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219, 64-bit
2022-10-29 09:21:51.481 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2022-10-29 09:21:51.481 UTC [1] LOG:  listening on IPv6 address "::", port 5432
Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start

waiting for server to start....2022-10-29 08:53:12.357 UTC [36] LOG:  starting PostgreSQL 13.8 on x86_64-pc-linux-musl, compiled by gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219, 64-bit
2022-10-29 08:53:12.360 UTC [36] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-10-29 08:53:12.366 UTC [37] LOG:  database system was shut down at 2022-10-29 08:53:12 UTC
2022-10-29 08:53:12.369 UTC [36] LOG:  database system is ready to accept connections
 done
server started
CREATE DATABASE


/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

waiting for server to shut down....2022-10-29 08:53:12.544 UTC [36] LOG:  received fast shutdown request
2022-10-29 08:53:12.546 UTC [36] LOG:  aborting any active transactions
2022-10-29 08:53:12.546 UTC [36] LOG:  background worker "logical replication launcher" (PID 43) exited with exit code 1
2022-10-29 08:53:12.546 UTC [38] LOG:  shutting down
2022-10-29 08:53:12.561 UTC [36] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.


PostgreSQL Database directory appears to contain a database; Skipping initialization

2022-10-29 09:21:51.486 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-10-29 09:21:51.492 UTC [21] LOG:  database system was shut down at 2022-10-29 08:53:48 UTC
2022-10-29 09:21:51.496 UTC [1] LOG:  database system is ready to accept connections

weirdly enough i cant find anywhere in my dockerfile or settings.py etc… where the number 5432 appears.

why can i not connect to the postresql database?

what more information may be required to answer?


Bonus info below

im on windows 10

following this example - YouTube

Pc_pX0 (59 mins in )

Docker version 20.10.17

django version 4.1.2

heres a screenshot to prove im not crazy

This would be better posted on a site like Stack Overflow. Envato doesn’t really mess with Docker.

5432 is the default port for postgres. If that database is running in a container then localhost:5432 won’t work unless you map the port. If it worked before then postgres was installed on the server outside of docker or the port was previously mapped.

You didn’t post a dockerfile or docker-compose so I can’t say for certain.