Docker- django throws error while connecting to postgres: psycopg2.OperationalError: could not connect to server: Connection refused

change HOST to:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': 'password',
        'HOST': 'db',
        'PORT': '5432',
    }
}

0.0.0.0 is not a valid IP, beside you need to connect using the service name since compose will resolve it for you

Leave a Comment