DEV Community

Launching a django webserver in Docker

jess unrein on December 05, 2023

Every single time I have to set up Docker for a new web server I forget a couple key things on how to set it up. This little post is mostly a note ...
Collapse
 
mellen profile image
Matt Ellen

Great breakdown of the problem. I hope I remember it next time I'm scratching my head over docker.

Collapse
 
kwnaidoo profile image
Kevin Naidoo • Edited

This is a good start. Just some suggestions:

A virtual environment will probably work a lot better unless, of course, you have docker-compose with multiple services.

Gunicorn is probably better than "run server" inside a container. This will give you more of prod-like server.

gunicorn -w 2 -b 127.0.0.1:8000 djangoapp.wsgi:application
Enter fullscreen mode Exit fullscreen mode
Collapse
 
thejessleigh profile image
jess unrein

Yup - as I explain at the beginning of the post, this was a quick and dirty solution to get around an operating system limitation, not a tutorial on production-like builds. Also, fwiw, I would recommend using uvicorn over gunicorn since it supports both wsgi and asgi.