This is Django tutorial in steroids, I wanted to go through the tutorial using a configuration that is more close to production.
I am running the django app with gunicorn, using postgres as the database, the django app is behind nginx and everything is running out of Docker containers orchastrated with docker-compose.
I've just finished going throught Django tutorial so the adventure on this repository is over, however have fun picking a start point:
Branch with reusuable-apps advanced tutorial
I am running this on a Macbook air running Yosemite with boot2docker.
- git clone this repo
- boot2docker up
- sh rebuild_docker.sh
- run migrations in your Django instance:
docker-compose run django /bin/sh -c 'cd mysite;python manage.py migrate'
- access it in your browser! https://192.168.59.103/ for me, run boot2docker ip to know where it is running.
Compose is a tool for defining and running multi-container applications with Docker. With Compose, you define a multi-container application in a single file, then spin your application up in a single command which does everything that needs to be done to get it running.
https://docs.docker.com/compose/
We have three containers: Nginx, Postgres and a Django App.
-
django
- Built from ./Dockerfile, running gunicorn to serve our django app.
-
postgres
- Just the basic image from DockerRegistry.
-
nginx
- We are building it from nginx/Dockerfile. In our nginx/nginx.conf we are basically proxying django to gunicorn and serving static files which gunicorn doesn't do for us.
Created to make life easier:
- Build your docker-compose file.
- docker-compose build
- Runs your containers on detached mode.
- docker-compose up -d
- Check if they are all running.
- docker-compose ps
use docker-compose run CONTAINER_NAME command
for example:
-
Testing polls app
- docker-compose run django /bin/sh -c 'cd mysite;python manage.py test polls'
-
Running ls
- docker-compose run django /bin/sh -c 'ls'
-
Running Python directly
- docker-compose run django python
use docker-compose logs CONTAINER_NAME
This project first started as me following the awesome introduction from Andrew T. Baker at the PyCon US 2015 link