As I progress with my Django projects, I have been looking to Docker to help build, test and deploy the project. Below I describe why I am using Docker, and in future posts, I will document how I use it locally and with AWS. When building a project, I have the following goals:
1) Reduce the development build, run and debug cycle as much as possible.
2) CI setup should be easy, dependable and locally debuggable
3) Deploying should be as automatic as possible
4) Have confidence in what you are deploying
There are three distinct environments that I support.
- Local Django Development environment.
- Run Django in a docker container locally (CI, Test etc.)
- Run Django in a cloud environment (AWS in this case)
When developing every second that gets between me writing some code and being able to test or run it is going to be multiplied out during the days and weeks of development. If it is slow at the start of a project, it is going to painful as the project grows. Building and deploying Docker containers can be quick, but it still adds extra time to the build process. If a developer is doing this many times a day an extra 10 to 20 seconds add up very quickly. For development work, I tend to work with all the services running on my local machine.
I use two different setups with my docker containers. The first setup is for running locally, such as in CI Tests, which has four docker containers to create a local environment needed to run the app. On Amazon, the deployment setup relies on some Amazon AWS Services to provide the database, message store and caching, so those are not be needed.
The local version of the app uses NGINX as a reverse proxy for the Django and serves static files. Postgres provides the database backend, and Redis is used to provide a caching and message store.
For production deployments, AWS services replace the Postgres and Redis containers. The AWS Load Balancer provides a reverse proxy in front of the web services. With this, NGINX doesn’t need to provide a reverse proxy for Django. NGINX is still needed to serve the static files for our website, and the load balancer uses routes to determine the web server to be used.
In the next series of articles, I will detail how I set up these environments using Docker Compose and Django settings to make this usable.
Leave a Reply