title: Postgres django.db.utils.OperationalError: could not connect to server: Connection refused
body: <p>Trying to run my django server in a docker, but the postgres port is already being used? When I run "docker-compose up", I receive this error:</p>
  
  <pre><code>django.db.utils.OperationalError: could not connect to server: Connection refused
      Is the server running on host "127.0.0.1" and accepting
      TCP/IP connections on port 5432?
  
  ERROR: Service 'web' failed to build: The command '/bin/sh -c python manage.py migrate' returned a non-zero code: 1
  </code></pre>
  
  <blockquote>
    <p>sudo service postgresql status</p>
  </blockquote>
  
  <p>returns:</p>
  
  <pre><code>9.6/main (port 5432): online
  </code></pre>
  
  <blockquote>
    <p>sudo lsof -nP | grep LISTEN</p>
  </blockquote>
  
  <p>returns:</p>
  
  <pre><code>postgres  15817         postgres    3u     IPv4            1022328        0t0        TCP 127.0.0.1:5432
  </code></pre>
  
  <p>I tried to run "sudo kill -9 15817", but docker-compose up still receives the same error.</p>
  
  <p><strong>Docker-compose.yml</strong></p>
  
  <pre><code>version: '3'
  
  services:
    db:
      image: postgres
    web:
      build: .
      command: python manage.py runserver 0.0.0.0:8000
      volumes:
        - .:/code
      ports:
        - "8000:8000"
      depends_on:
        - db
  </code></pre>
  
  <p><strong>settings.py</strong></p>
  
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql',
          'NAME': 'stemletics',
          'USER': 'stemleticsadmin',
          'PASSWORD': 'changeme',
          'HOST': '127.0.0.1', # set in docker-compose.yml
          'PORT': 5432 # default postgres port
      }
  }
  </code></pre>