I want to run Django in a simple Docker container.
First I built my container with Docker-file. There wasn\'t anything special in it (only FROM, RUN and COPY commands)
The problem is that you're exposing the development server to 127.0.0.1
inside your Docker container, not on the host OS.
If you access another console to your container and do a http request to 127.0.0.1:8000
it will work.
The key is to make sure the Docker container exposes the development server to all IPv4 addresses, you can do this by using 0.0.0.0
instead of 127.0.0.1
.
Try running the following command to start your Django development server instead:
python manage.py runserver 0.0.0.0:8000
Also, for further inspiration, you can check out this working Dockerfile for hosting a Django application with the built-in development server https://github.com/Niklas9/django-unixdatetimefield/blob/master/Dockerfile.
You need to expose port 8000 in your Dockerfile and run a WSGI server like gunicorn. If you follow the steps here you should be good... https://semaphoreci.com/community/tutorials/dockerizing-a-python-django-web-application
I agree with Niklaus9 comments. If I could suggest an enhancement try
python manage.py runserver [::]:8000
The difference is that [::] supports ipv6 addresses.
I also noticed some packages for mongodb. If you want to test and dev locally you can create docker containers and use docker compose to test your app on your machine before deploying to dev/stage/prod environment.
You can find out more about how to set up a Django app linked to a database backend in docker on this tutorial http://programmathics.com/programming/docker/docker-compose-for-django/ (Disclaimer: I am the creator of that website)