[Django]-Connect to a PostgreSQL database on a Docker container

8đź‘Ť

âś…

When using docker-compose, you “discover” services via hostname. Your database service is defined with label postgres. Use it as a hostname in your application cofiguration.

Also password and DB name must be in sync with your app config. This is done via environment variables for postgres service:

services:
  postgres:
    environment:
      - POSTGRES_PASSWORD: "mysecretpassword"
      - POSTGRES_DB: "wgomanager"
  # rest of docker-compose.yml

Reffer to image docs on how various env. vars affect service configuration.

👤srigi

Leave a comment