title: pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
body: <p>I am trying to use docker-compose with my django-rest app. 
  When I run it myself <code>python manage.py runserver</code> it works well.</p>
  
  <p>If I am trying to use docker-compose <code>sudo docker-compose up</code> it also runs the server but when I open the page in the browser I get an error.</p>
  
  <pre><code>pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
  </code></pre>
  
  <p>I already have db, so I am just using this lines in <code>settings.py</code></p>
  
  <pre><code>MONGODB_DATABASES = {
      "default": {
          "name": 'api',
          "host": 'localhost',
         "port": 27017
      },
  }
  </code></pre>
  
  <p>Here is my Dockerfile:</p>
  
  <pre><code>FROM python:3
  ENV PYTHONUNBUFFERED 1
  RUN mkdir /code
  WORKDIR /code
  COPY . /code
  RUN pip install -r requirements.txt
  </code></pre>
  
  <p>My docker-compose.yml:</p>
  
  <pre><code>version: '3.0'
  services:
    web:
      build: .
      command: python manage.py runserver 0.0.0.0:8000
      volumes:
        - .:/code
      ports:
        - "8000:8000"
    mongo:
      image: mongo
  </code></pre>
  
  <p>Already tried this:</p>
  
  <p><a href="https://stackoverflow.com/questions/7744147/pymongo-keeps-refusing-the-connection-at-27017">Pymongo keeps refusing the connection at 27017</a></p>