title: django container can't access postgres container
body: <p>I am trying to have my database and my django rest api connect using docker-compose. However, my django container is giving me this error:</p>
  
  <pre><code>django.db.utils.OperationalError: could not connect to server: Connection refused
  Is the server running on host "localhost" (127.0.0.1) and accepting
  TCP/IP connections on port 5432?
  could not connect to server: Cannot assign requested address
  Is the server running on host "localhost" (::1) and accepting
  TCP/IP connections on port 5432?
  </code></pre>
  
  <p>Postgres starts up normally, and I am able to access it locally using the terminal. I'm just not sure why my django container can't connect.</p>
  
  <pre><code>$ psql -h 0.0.0.0 -p 5432 -U bli1 -d redribbon
  Password for user bli1:
  psql (12.1)
  Type "help" for help.
  </code></pre>
  
  <p>Within my <code>settings.py</code> for django this is my database values</p>
  
  <pre><code>DATABASES = {
      "default": {
          "ENGINE": "django.db.backends.postgresql_psycopg2",
          "NAME": "redribbon",
          "USER": "bli1",
          "PASSWORD": "password",
          "HOST": "0.0.0.0",
          "PORT": "5432",
      }
  }
  </code></pre>
  
  <p>docker-compose.yml</p>
  
  <pre><code>version: "3"
  services:
    postgres:
      image: postgres:latest
      restart: always
      ports:
        - "5432:5432"
      volumes:
        - ./pgdata:/var/lib/postgresql/data/
      environment:
        POSTGRES_DB: redribbon
        POSTGRES_USER: bli1
        POSTGRES_PASSWORD: password
    api:
      build:
        dockerfile: Dockerfile.dev
        context: ./redribbon-api
      command: python manage.py runserver 0.0.0.0:8000
      volumes:
        - ./redribbon-api/api:/usr/src/api
      depends_on:
        - postgres
      ports:
        - "8000:8000"
  </code></pre>
  
  <p><strong>updates:</strong></p>
  
  <p>Within the django container, I am able to ping postgres and got this as a response </p>
  
  <pre><code># ping postgres
  PING postgres (172.19.0.2) 56(84) bytes of data.
  64 bytes from redribbon_postgres_1.redribbon_default (172.19.0.2): icmp_seq=1 ttl=64 time=0.175 ms
  64 bytes from redribbon_postgres_1.redribbon_default (172.19.0.2): icmp_seq=2 ttl=64 time=0.096 ms
  64 bytes from redribbon_postgres_1.redribbon_default (172.19.0.2): icmp_seq=3 ttl=64 time=0.097 ms
  </code></pre>
  
  <p>I even tried changing <code>"HOST": "0.0.0.0",</code> to <code>"HOST": "postgres",</code> in my <code>settings.py</code> but I am getting the same error as above</p>