Home > Software engineering >  Can't run django rest framework with docker
Can't run django rest framework with docker

Time:09-13

I'm currently learning Docker and django rest at the same time. When i run the command python3 manage.py runserver I can access to django admin page from http://localhost:8000/admin/, but when i run docker run -p 80:80 docker_django_tutorial the page is anccesible. (docker_django_tutorial is the name of my docker image) I guess i need to add somewhere python3 manage.py runserver in my dockerfile ?

Here is my Dockerfile:

#Use the Python3.7.2 container image
FROM python:3.7.2-stretch
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]

and here my file requirements.txt:

Django==3.1.1
djangorestframework

CodePudding user response:

You're telling Django to listen on port 8000 but then telling Docker to expose port 80. Use -p 8000:8000 instead. If you want it to listen on port 80, you can use -p 80:8000. The first number is host (your system) port and the second is container port (Django).

  • Related