title: could not translate host name "db" to address when running Django test in Docker through PyCharm
body: <p>I have a simple Django project with a PostgreSQL backend:</p>
  
  <pre><code>version: '3'
  services:
    db:
      image: postgres:12
      ports:
        - '5432:5432'
      volumes:
        - postgres_data:/var/lib/postgresql/data/
      environment:
        POSTGRES_USER: pycharm
        POSTGRES_PASSWORD: pw123
        POSTGRES_DB: pycharm
  
    app:
      build: .
      command: python manage.py runserver 0.0.0.0:8000
      ports:
        - '8000:8000'
      volumes:
        - .:/app
      depends_on:
        - db
  
  volumes:
    postgres_data:
  </code></pre>
  
  <p>With the following database settings in <code>settings.py</code>:</p>
  
  <pre><code>DATABASES = {
      "default": {
          "ENGINE": "django.db.backends.postgresql",
          "NAME": "pycharm",
          "USER": "pycharm",
          "PASSWORD": "pw123",
          "HOST": "db",
      }
  }
  </code></pre>
  
  <p>And a simple test:</p>
  
  <pre><code>from django.test import TestCase
  
  class MyTestCase(TestCase):
  
      def test_example(self):
          assert 1 == 1
  </code></pre>
  
  <p>Everything works fine when I run the project with docker-compose:</p>
  
  <pre><code>docker-compose up
  </code></pre>
  
  <p>I can exec into the container running the django app and successfully execute the test:</p>
  
  <pre><code>docker-compose run app bash
  $ python manage.py test demo.tests.MyTestCase
  Creating test database for alias 'default'...
  System check identified no issues (0 silenced).
  .
  ----------------------------------------------------------------------
  Ran 1 test in 0.002s
  
  OK
  Destroying test database for alias 'default'...
  </code></pre>
  
  <p>I want to run the test in PyCharm, instead of having to exec into the container every time. I've setup the remote interpreter using Docker. However, when I run the test in PyCharm I get the following error:</p>
  
  <blockquote>
    <p>django.db.utils.OperationalError: could not translate host name "db" to address: Name or service not known</p>
  </blockquote>
  
  <p>It appears the app container can't find the database container when I run the test in PyCharm. This brings about two questions:</p>
  
  <ol>
  <li><p>Is there anyway to fix this so the app container can find the database container? I know <a href="https://stackoverflow.com/a/47663730/6611672">docker networking on localhost is tricky</a>.</p></li>
  <li><p>Is there anyway to setup the tests so they don't need to connect to the database container? I feel like <code>Django</code> or <code>psycopg2</code> should be able to spin up a mock PostgreSQL service for the tests.</p></li>
  </ol>
  
  <p>One way I've fixed this in the past is to <a href="https://stackoverflow.com/a/6353576/6611672">use sqlite3 for my test database</a>; however, I'm using fields that are not compatible with sqlite (such as <a href="https://docs.djangoproject.com/en/3.0/ref/contrib/postgres/fields/#arrayfield" rel="nofollow noreferrer">ArrayField</a>) so that's not an option.</p>