Django connection to postgres by docker-compose

Each container in docker by default gets its own hostname and IP. When compose spins up the containers for you, it also places all of the containers on a network by default to permit DNS based discovery.

What this means is that your database is not reachable on localhost, but you can reach it by the service name “db”. Change this line in your settings.py:

    'HOST': 'localhost',

to:

    'HOST': 'db',

Leave a Comment