settings.py file:
from decouple import config
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': config('POSTGRES_DB'),
'USER': config('POSTGRES_USER'),
'PASSWORD': config('POSTGRES_PASSWORD'),
'HOST': config('DB_HOST'),
'PORT': config('POSTGRES_PORT'),
}
}
.env file:
# DJANGO
SECRET_KEY='foobar'
DEBUG=False
ALLOWED_HOSTS=localhost 127.0.0.1
# DATABASE
POSTGRES_DB=cheflist
POSTGRES_USER=postgres
POSTGRES_PASSWORD=123123
POSTGRES_HOST=localhost
POSTGRES_PORT=5433
DB_HOST=0.0.0.0
docker-compose.yml file:
version: "3.8"
services:
db:
container_name: db
image: postgres:13-alpine
restart: always
env_file:
- ./.env
volumes:
- ./postgres_data/db:/var/lib/postgresql/data/
ports:
- 5433:5433
The first question is that when I up the postgres image, everything goes well, BUT a message comes out in the logs:
db | 2022-09-20 10:23:05.118 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db | 2022-09-20 10:23:05.119 UTC [1] LOG: listening on IPv6 address "::", port 5432
db | 2022-09-20 10:23:05.123 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db | 2022-09-20 10:23:05.142 UTC [21] LOG: database system was shut down at 2022-09-20 10:19:44 UTC
db | 2022-09-20 10:23:05.163 UTC [1] LOG: database system is ready to accept connections
For some reason, the port to which postgres is connected in docker is 5432, although I specified 5433.
The second question. When I run the python manage.py runserver terminal throws an error:
django.db.utils.OperationalError: connection to server at "0.0.0.0", port 5433 failed: Cannot assign requested address (0x00002741/10049)
Is the server running on that host and accepting TCP/IP connections?
... and it seems to me that this has something to do with my first question, since initially the image is not connected to the right port