Django Docker best practices for dummies?
Production-ready Docker setup for Django applications
Best way to deploy a Django application (Ansible vs docker-compose)
When would I use Docker?
Let me start of my saying that I really, really like docker. Its a wonderful technology that is absolutely production ready. Once you've created proper images, you're able to scale to a silly degree, with automatic load balancing, failover and so much more... but honestly? you are probably better off not using it.
Docker containers are meant to be small, each application getting its own container. You're still able to run them simultaneously using provisioning tools, whatever they might be.
But if you're not going all in, you'll quickly get into a world of pain. Logrotate? Networking? Storage? Monitoring?
This and more are all things that need to work if this service is meant to be used in production. And its definitely not trivial to setup.
And we've not even started with development yet. if something doesnt work, you need to debug so many layers of abstractions that it will quickly feel horrible.
Docker is great if you want to go into CI/CD though. Just create a container from SCM and deploy it into the kubernetes cluster, fully configured to pipe all logs to a logserver. Its simply great at scale.
Also, docker containers are NOT virtual machines! if you use them like that, you'll quickly get massive images that take ages to start and force you to actually enter the container to debug. Once you're there, you'll quickly get why https://www.youtube.com/watch?v=PivpCKEiQOQ got created
More on reddit.comVideos
I have created a fair few small (and one giant sprawling) Django project that are in use by small groups of consistent people (think work groups).
Up to this point, I've built sites inside python venv's and hosted with Apache mod_wsgi, all on a couple of AWS virtual machines (EC2 instances).
As I make more little Django sites, it seems like it's getting time to move into containers to keep a bit more explicit definition around package requirements/versions, transition between servers, easier local testing, etc. It seems like most tutorials out there are for toy projects on bare metal (raises hand) or using Django for Kubernetes style dynamic deployment, load balancing, etc.
Does anyone have a good resource for building / deploying relatively simple Django projects to a container for general containerization. Things like, packaging process, pros and cons of running the database in the same container / different container / bare metal, etc.
I always feel like reinventing the wheels, every time I write Dockerfile for my Django applications. Few things which I realized are critical for Docker setup for production environment are image size, security, incorporation of Django commands like `collectstatic` and `migrate`, side-effects in scaling up and down in Kubernetes or some other setup, etc.
In this blog, I have tried to create a reusable template and share the reasoning behind it so as to initiate discussion for further improvement.
The (near) Perfect Dockerfile for Django Applications