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