title: difference between localhost and postgres for host in docker
body: <p>I am developing a django app and trying to run it inside docker. I have an issue that I could not understand so far. while running the app with <code>docker-compose</code>, it seems that the <code>web</code> app cannot connect to the database when i use these configurations:</p>
  
  <pre><code>DATABASES = {
      'default': {
         'ENGINE': 'django.db.backends.postgresql_psycopg2',
         'NAME': 'my_db',
         'USER': 'my_user',
         'PASSWORD': '',
         'HOST': 'localhost',
         'PORT': '5432',
      }
  </code></pre>
  
  <p>but once I change the host to <code>postgres</code>, it works. like this</p>
  
  <pre><code>DATABASES = {
      'default': {
         'ENGINE': 'django.db.backends.postgresql_psycopg2',
         'NAME': 'my_db',
         'USER': 'my_user',
         'PASSWORD': '',
         'HOST': 'postgres',
         'PORT': '5432',
      }
  </code></pre>
  
  <p>what is the difference between <code>postgres</code> and <code>localhost</code>. One is running without and issue inside docker and not in development environment in my mac and the other one is the opposite.</p>
  
  <pre><code># docker-compose.yml    
  version: '3'
  
      services:
        db:
          image: postgres
          expose: 
            - "5432"
        web:
          build: .
          command: python3 manage.py runserver 0.0.0.0:8000
          volumes:
            - .:/code
          ports:
            - "8000:8000"
          depends_on:
            - db
  </code></pre>