Test Django Applications Using Docker Containers

Earlier I had an issue in which my machine wasn’t able to connect to the Django webserver (runserver) inside the container, even though I had the correct port published using Docker, so, this is the solution.

By default the app runs on and has ALLOWED_HOSTS = [] this means that the app will only allow connections from within the container but since we want to access to the application from our local machine we need to change the following:

Under <yourappname>/settings.py :


And when you run the application pass the following arguments:

# python manage.py runserver

Instead of ‘binding’ to the default by using it will bind to every interface (lo, ethX, etc).

Hope it helps!