title: Docker-compose: App container can't connect to Postgres
body: <p>Using docker-compose, I'm trying to view a Flask app from <code>manage.py runserver</code> that connects with a postgres image but I get the following error:</p>
  
  <pre><code>sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
      Is the server running on host "0.0.0.0" and accepting
      TCP/IP connections on port 5432? 
  </code></pre>
  
  <p><strong>MY COMPOSE FILE</strong></p>
  
  <pre><code>version: '3.1'
  services:
    app:
      build: .
      ports:
        - 5000:5000
      volumes:
        - /Users/sammy/Projects/my_flask_app:/my_flask_app
      container_name: my_flask_app_1
      depends_on:
        - db
      entrypoint: ["python", "manage.py", "runserver"]
    db:
      image: postgres:10
      restart: always
      container_name: my_app_db_1
      environment:
        POSTGRES_USER: ubuntu
        POSTGRES_PASSWORD: pickles
        POSTGRES_DB: db
      ports:
        - 5432:5432
  </code></pre>
  
  <p><strong>FROM MY APP'S <code>settings.py</code> FILE</strong></p>
  
  <pre><code>POSTGRES = {
      'user': "ubuntu",
      'pw': "pickles",
      'db': "db",
      'host': os.getenv('IP', '0.0.0.0'),
      'port': '5432',
  }
  SQLALCHEMY_DATABASE_URI = 'postgresql://%(user)s:\
  %(pw)s@%(host)s:%(port)s/%(db)s' % POSTGRES
  </code></pre>
  
  <p>It builds and runs the app well as I can visit the site and see the Werkzeug traceback interpreter. I'm failing either on the configuration of the Postgres container itself or my Flask's connection to it.</p>
  
  <ul>
  <li>Are the environmental variables correct?</li>
  <li>Do I need to specify a volume for the DB? If so, why? I haven't understood the point of that other than tucking the username/pass into environmental variables. </li>
  </ul>