title: Pycharm Docker Debugger Unable to Connect to DB in Docker
body: <p>I am running a PyCharm 2018.2 version.
  I have my django code running on a docker instance and the Postgres running on another docker instance.
  My docker-compose.yml file is here</p>
  
  <pre><code>    version: "2.3"
  
  services:
    cv_db:
      container_name: cv_db
      image: postgres:10.3-alpine
      restart: always
      ports:
        - "9081:5432"
      environment:
        POSTGRES_USER: root
        POSTGRES_PASSWORD: ****
        POSTGRES_DB: cv
      volumes:
        - cv_db:/var/lib/postgresql/data
      expose:
        - "9081:5432"
  
    cv_redis:
      container_name: cv_redis
      image: redis:4.0.5-alpine
      restart: always
      ports:
        - "6379:6379"
  
    cv:
      container_name: cv
      image: cv
      restart: always
      depends_on:
        - cv_redis
        - cv_db
      ports:
        - "9080:9080"
        - "8080:8080"
      expose:
        - "9080"
      build:
        context: .
        args:
          http_proxy:
          https_proxy:
          no_proxy:
          TF_ANNOTATION: "no"
          USER: "django"
          DJANGO_CONFIGURATION: "production"
          WITH_TESTS: "no"
      environment:
        DJANGO_MODWSGI_EXTRA_ARGS: ""
        DJANGO_LOG_SERVER_URL: ""
      volumes:
        - cvat_data:/home/django/data
        - cvat_keys:/home/django/keys
        - cvat_logs:/home/django/logs
        - ./share:/home/django/share
  
  volumes:
    cv_db:
    cv_data:
    cv_keys:
    cv_logs:
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql',
          # 'HOST': 'cv_db',
          'HOST': 'localhost',
          'PORT': '9801',
          'NAME': 'cv_dev',
          'USER': 'root',
          'PASSWORD': os.getenv('POSTGRES_PASSWORD', '****'),
      }
  </code></pre>
  
  <p>I am using the django debugger:
  Edit Configuration Settings are below:</p>
  
  <pre><code>Host: 0.0.0.0 Port: 9080
  Run Browser: http://0.0.0.0:9080/
  </code></pre>
  
  <p>WHen I click on debug, I get the error saying it cant connect to Database:</p>
  
  <pre><code>django.db.utils.OperationalError: could not connect to server: Connection refused
      Is the server running on host "localhost" (127.0.0.1) and accepting
      TCP/IP connections on port 9081?
  could not connect to server: Cannot assign requested address
      Is the server running on host "localhost" (::1) and accepting
      TCP/IP connections on port 9081?
  </code></pre>
  
  <p>what might be going wrong?</p>