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
230
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.3k
Django tasty salad- DOs and DON'Ts using Celery
siloraptor
0
800
An educational retro game using only Python? Challenge Accepted!
siloraptor
0
140
Packaging Django Projects for PyPI
siloraptor
1
500
Liberation and modernization of legacy government data using Django
siloraptor
0
280
Other Decks in Programming
See All in Programming
はてなにおけるfujiwara-wareの活用やecspressoのCI/CD構成 / Fujiwara Tech Conference 2025
cohalz
3
4.1k
Linux && Docker 研修/Linux && Docker training
forrep
23
4.2k
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
610
ESLintプラグインを使用してCDKのセオリーを適用する
yamanashi_ren01
2
450
Amazon Bedrock Multi Agentsを試してきた
tm2
1
260
自動で //nolint を挿入する取り組み / Gopher's Gathering
utgwkk
1
200
[Fin-JAWS 第38回 ~re:Invent 2024 金融re:Cap~]FaultInjectionServiceアップデート@pre:Invent2024
shintaro_fukatsu
0
380
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
3
1.1k
為你自己學 Python
eddie
0
550
時計仕掛けのCompose
mkeeda
1
240
月刊 競技プログラミングをお仕事に役立てるには
terryu16
2
1.3k
ATDDで素早く安定した デリバリを実現しよう!
tonnsama
1
2.5k
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.2k
Designing for humans not robots
tammielis
250
25k
It's Worth the Effort
3n
184
28k
For a Future-Friendly Web
brad_frost
176
9.5k
Designing for Performance
lara
604
68k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
The Cult of Friendly URLs
andyhume
78
6.2k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
128
19k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Site-Speed That Sticks
csswizardry
3
310
Practical Orchestrator
shlominoach
186
10k
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!