title: PostgreSQL cannot connect to fastapi applicaiton via SQLalchemy utilizing docker-compose
body: <pre><code>test-api_1  | sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
  test-api_1  |   Is the server running on host "0.0.0.0" and accepting
  test-api_1  |   TCP/IP connections on port 5432?
  test-api_1  | 
  test-api_1  | (Background on this error at: http://sqlalche.me/e/e3q8)
  partnerup-api_test-api_1 exited with code 1
  </code></pre>
  
  <p>This is the error I am getting--- it is relatively vague and does not provide much more information. </p>
  
  <p>From the docker-compose cli, I get the following:</p>
  
  <pre><code>my_postgres | 2019-11-03 23:05:21.746 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
  my_postgres | 2019-11-03 23:05:21.746 UTC [1] LOG:  listening on IPv6 address "::", port 5432
  my_postgres | 2019-11-03 23:05:21.758 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
  my_postgres | 2019-11-03 23:05:21.817 UTC [51] LOG:  database system was shut down at 2019-11-03 23:05:21 UTC
  my_postgres | 2019-11-03 23:05:21.847 UTC [1] LOG:  database system is ready to accept connections
  </code></pre>
  
  <p>This is confusing because it seems to be listening but the base api application doesn't recognize via sql alchemy.</p>
  
  <p>I have tried to navigate to postgres.conf but found that listen_adress = '*'</p>
  
  <p>Beyond this I dont know what could be the issue. </p>
  
  <p>database.py</p>
  
  <pre><code>from sqlalchemy import create_engine
  from sqlalchemy.ext.declarative import declarative_base
  from sqlalchemy.orm import sessionmaker
  
  
  SQLALCHEMY_TRACK_MODIFICATIONS = False
  ## from sql alchemy docs --- format: postgresql://&lt;user&gt;:&lt;password&gt;@&lt;host&gt;:&lt;port&gt;/&lt;database&gt;
  SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:dbpw@0.0.0.0:5432/partnerup'
  engine = create_engine(SQLALCHEMY_DATABASE_URI)
  SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
  
  Base = declarative_base()
  </code></pre>
  
  <p>docker-compose.yml</p>
  
  <pre><code>version: '3' #docker-compose version
  services:       #containers in the network
    test-api:
      build: .
      ports:
        - 5000:5000 #port to go to to get a local version of the app
      volumes:
        - ./apps/api/app:/app
      working_dir: /app
      depends_on: 
        - db
      command:
        ['uvicorn', 'main:app', '--host', '127.0.0.1', '--port', '5000']
        #may integrate later
    db:
      image: "postgres:11"
      container_name: "my_postgres"
      restart: always 
      ports:
        - "5432:5432"
      environment:
        POSTGRES_USER: 'postgres'
        POSTGRES_PASSWORD: 'dbpw'
        POSTGRES_DATABASE: 'partnerup'
        POSTGRES_HOST: 'localhost'
        POSTGRES_PORT: '5432'
      volumes:
            # this command will create database as described in init file 
       # - .:/docker-entrypoint-initdb.d/       
        - db_volume:/var/lib/postgresql
  volumes:
    db_volume: {}
  </code></pre>
  
  <p>I expect that I should be able to verify a connection but I keep getting that pesky error message.</p>