Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Dockerizing Django projects
Search
Roberto Rosario
April 15, 2016
Programming
0
220
Dockerizing Django projects
Pros and Cons of the different ways there are to turn a Django project into a Docker container.
Roberto Rosario
April 15, 2016
Tweet
Share
More Decks by Roberto Rosario
See All by Roberto Rosario
Geospatial three amigos: Python, Leaflet, and ElasticSearch
siloraptor
1
460
OpenHolter project: D.I.Y. Electrocardiography using Arduino and Django
siloraptor
0
1.2k
Django tasty salad- DOs and DON'Ts using Celery
siloraptor
0
750
An educational retro game using only Python? Challenge Accepted!
siloraptor
0
130
Packaging Django Projects for PyPI
siloraptor
1
490
Liberation and modernization of legacy government data using Django
siloraptor
0
270
Other Decks in Programming
See All in Programming
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
880
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
580
Amazon Qを使ってIaCを触ろう!
maruto
0
400
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Quine, Polyglot, 良いコード
qnighy
4
640
Contemporary Test Cases
maaretp
0
130
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Click-free releases & the making of a CLI app
oheyadam
2
110
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
330
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Site-Speed That Sticks
csswizardry
0
23
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Building Adaptive Systems
keathley
38
2.3k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
RailsConf 2023
tenderlove
29
900
What's new in Ruby 2.0
geeforr
343
31k
Transcript
Dockerizing Django projects Roberto Rosario robertorosario.com
Who am I? robertorosario.com
[email protected]
Roberto Rosario
None
What is Docker?
Docker provides an integrated technology suite that enables development and
IT operations teams to build, ship, and run distributed applications anywhere.
In human now.
Containers.
Lightweight virtualization. ie: No video hardware emulation.
Some devops now hate me.
Deploy everywhere.
Easy scalability.
Even auto scaling.
Deploying Django: Old school.
None
None
None
None
None
None
Deployed! Congratulations!
Your users have now quadrupled!
None
None
Server are old, let’s go virtual!
None
None
None
Different technology, same problem.
None
None
None
None
Django and Docker?
Configuration files.
First steps.
None
None
Classes Instances
More devops hate me now.
None
Dockerfile
An entire OS for just a part of the Django
project?
Not to worry.
None
None
Your Django project
Your Django project
Your Django project image Your Django project
Base image = Base class Your image = Subclass
Pretty much every devops hate me at this point.
One size doesn’t fit all.
Monolithic
App Workers Web server
docker run --name postgres -e POSTGRES_DB=mayan -e POSTGRES_USER=mayan -e POSTGRES_PASSWORD=mysecretpassword
-v /var/lib/postgresql/data -d postgres docker run --name redis -d redis docker run --name mayan-edms -p 80:80 --link postgres:postgres --link redis:redis -e POSTGRES_DB=mayan -e POSTGRES_USER=mayan -e POSTGRES_PASSWORD=mysecretpassword -v /usr/local/lib/python2.7/dist- packages/mayan/media -d mayanedms/monolithic
• Single download • Low entry barrier • Easiest to
maintain • Big size download • Not good for scaling • Same VM/Server problem
Split
App Workers Web server
Split ~ Frontend + Backend
• Scale individually • Smaller download • Best approach for
production • Harder to setup • Need documentation • Several DockerFiles
Mixed
Role Frontend Backend
None
• Single download • Can reuse configuration file templates •
Single core repo • Bigger size download
Lean
Lean = Split without any 3rd party
App Workers Web server
• Smallest download • Hardest to configure • Might not
scale best • Might violate port export concept
Django + uWSGI NGINX
Django + uWSGI NGINX TCP Port uwsgi_pass 127.0.0.1:3031; socket =
127.0.0.1:3031
Django + uWSGI NGINX socket = /tmp/uwsgi.sock uwsgi_pass unix:///tmp/uwsgi.sock; ?
Django + uWSGI NGINX socket = /tmp/uwsgi.sock uwsgi_pass unix:///tmp/uwsgi.sock; Volume?
• Need to include NGINX config
$ docker run --name some-nginx -v /some/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
environment: - NGINX_HOST=foobar.com - NGINX_PORT=80 command: /bin/bash -c "envsubst <
/etc/nginx/conf.d/mysite.template > /etc/nginx/conf. d/default.conf && nginx -g 'daemon off;'"
Last approach
Kitchen sink
App Workers Database Web server Broker
• Single download • Lowest entry barrier • Biggest size
download • Terrible for scaling • Same VM/Server problem • Support 3rd party software
None
Educational purposes only
Don’t use in production
EVER!
Kitchen sink will freeze your servers
Devops don’t like frozen servers
None
Don’t turn your devops into Gordon Ramsay
Post init actions
migrate & collectstatic
None
None
None
None
Service synchronization
$ docker run --name postgres -e POSTGRES_DB=mayan -e POSTGRES_USER=mayan -e
POSTGRES_PASSWORD=mysecretpassword -v /var/lib/postgresql/data -d postgres $ docker run --name redis -d redis $ docker run --name mayan-edms -p 80:80 --link postgres:postgres --link redis:redis -e POSTGRES_DB=mayan -e POSTGRES_USER=mayan -e POSTGRES_PASSWORD=mysecretpassword -v /usr/local/lib/python2.7/dist- packages/mayan/media -d mayanedms/monolithic
Database connection error.
None
$ docker run --name postgres -e POSTGRES_DB=mayan -e POSTGRES_USER=mayan -e
POSTGRES_PASSWORD=mysecretpassword -v /var/lib/postgresql/data -d postgres $ docker run --name redis -d redis $ docker run --name mayan-edms -p 80:80 --link postgres:postgres --link redis:redis -e POSTGRES_DB=mayan -e POSTGRES_USER=mayan -e POSTGRES_PASSWORD=mysecretpassword -v /usr/local/lib/python2.7/dist- packages/mayan/media -d mayanedms/monolithic
$ docker run --name postgres -e POSTGRES_DB=mayan -e POSTGRES_USER=mayan -e
POSTGRES_PASSWORD=mysecretpassword -v /var/lib/postgresql/data -d postgres $ docker run --name redis -d redis $ docker run --name mayan-edms -p 80:80 --link postgres:postgres --link redis:redis -e POSTGRES_DB=mayan -e POSTGRES_USER=mayan -e POSTGRES_PASSWORD=mysecretpassword -v /usr/local/lib/python2.7/dist- packages/mayan/media -d mayanedms/monolithic until nc -z $POSTGRES_PORT_5432_TCP_ADDR $POSTGRES_PORT_5432_TCP_PORT; do echo "$(date) - waiting for postgres..." sleep 1 done
Service synchronization doesn’t belong in configuration files.
until nc -z $POSTGRES_PORT_5432_TCP_ADDR $POSTGRES_PORT_5432_TCP_PORT; do echo "$(date) - waiting
for postgres..." sleep 1 done until nc -z $RABBITMQ_PORT_5672_TCP_ADDR $RABBITMQ_PORT_5672_TCP_PORT; do echo "$(date) - waiting for rabbitmq..." sleep 1 done
More problems.
• Not foolproof • Mute services • nc is not
universal • API URL paths?
Solutions?
None
$ docker run -d --name mycontainer some-image-or-other $ docker run
--link mycontainer:mycontainer aanand/wait waiting for TCP connection to 172.17.0.105:5432......ok
Interesting, but...
None
An entire container to run nc.
Cool solution, wrong problem.
None
None
It’s the container manager’s responsibility.
None
None
Kubernetes approach
None
Port, path, initial delay & timeout!
None
None
Docker upstream native approach needed
None
None
Templating
Docker images are static. Less reusable.
None
Docker containers are configured with environment variables.
None
uWSGI support environment variables. NGINX doesn’t.
Docker upstream native approach needed
None
None
“Thank you for using Docker” “But your fix is in
another repository”
None
Options?
None
And then there is genius
None
None
Bonus
None
Can help with logs too
None
Demo time
Lessons learned?
None
None
None
None
None
Thank you!