Dockerify Django

Fekete György (f@pulilab.com)

Senior Full-Stack Developer

pulilab.com

https://github.com/pulilab/dockerizing-django

http://slides.com/gyorgyfekete/dockerify-django (this)

Docker is porn

Thank you!

  • https://docs.docker.com/compose/django/
  • https://realpython.com/blog/python/django-development-with-docker-compose-and-machine/
  • https://www.calazan.com/using-docker-and-docker-compose-for-local-django-development-replacing-virtualenv/

 

Docker

Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.

Docker 

VirtualMachine

Container

Why is it good?

  • Accelerate developer onboarding
  • Prototype faster
  • Try stuff out without the fear of causing conflict
  • DBAs and App Devs can have their own containers, later link them together
  • No environment inconsistencies
  • Scales perfectly

Why is it good? (more tech)

  • Docker uses btrfs (a copy-on-write filesystem) to keep track of filesystem diff's which can be committed and collaborated on with other users (like git)
  • Docker is a great image distribution model for server templates built with Configuration Managers (like Chef, Puppet, SaltStack, etc)
  • Docker has a central repository of disk images (public and private) that allow you to easily run different operating systems (DockerHUB)

Docker + Django ?

  • a lot of app dependencies (pip packages, bower, etc) - virtualenv vs docker
  • server app dependencies and configurations (nginx, gunicorn, uwsgi, redis, rabbitmq, postgres, postgis, mongodb, .....)
  • dev/local env vs staging/prod env differences

DEMO

DEMO

> docker-machine create -d virtualbox dev

 

Creating a new docker machine (Mac OS X)

DEMO

> eval "$(docker-machine env dev)"

 

Activate the new docker machine

DEMO

> docker-machine ls

 

List machines

DEMO

> docker-compose build

> docker-compose up -d

 

Build images

DEMO

> docker-compose run web python manage.py migrate

 

 

Migrate Django

DEMO

> docker-compose logs

 

 

Check logs

DEMO

> psql -h 192.168.99.100 -p 5432 -U postgres --password

 

 

Connect to DB

DEMO

> docker-machine create -d digitalocean --digitalocean-access-token=YOUR_TOKEN --digitalocean-region=ams3 production

 

 

PRODUCTION: create prod machine

DEMO

> eval "$(docker-machine env production)"

 

 

PRODUCTION: activate prod machine

DEMO

> docker-compose build

> docker-compose -f production.yml up -d

 

 

PRODUCTION: build prod image

DEMO

> docker ps

> docker exec dockerizingdjango_web_1 python manage.py migrate

 

 

PRODUCTION: run migrations on prod

dockerify django

By György Fekete

dockerify django

dockerify django

  • 1,497