SlideShare a Scribd company logo
by Anton Egorov
July 2016
Deliver Python Apps
with Docker
Who am I?
• Software Engineer, 10 years in web development
• Scripting mostly with Python
• 2 years using Docker, dockerized about 50
apps, 80% of them were Python apps
• Ex Lead Developer at ostrovok.ru
• CTO and Founder at sabaka.io
Plan
• Quick introduction to Docker
• App dockerization example
• Production deployment notes
• Treasure Goblin lives on special slides
Docker in a few slides
What is Docker?
• It’s an open-source project that automates
application deployment using containers
• Initial release was in March 2013
• Written in Go
• Works on Linux, OS X, Windows
Why Docker?
• The best tool for software packaging
• Easy to build, just follow best practices
• Fast at runtime, overhead is close to nothing
• You have identical installation at any
environment (dev, stage, prod)
• Predictable, easy to test, makes QA happy
Image
• An image is a container basis
• It’s a filesystem and a set of parameters to use at
runtime (libs, bins, your software)
• It doesn’t have a state and never changes
• Dockerfile contains instructions to build the
image
Container
• A container is a running instance of the image
• It consists of
• Docker image
• Execution environment
• Set of instructions
Data Volume
• Directory within one or more containers that
bypasses the Union File System
• Designed to persist data, independent of the
container’s life cycle
Notes
• Treat containers as read-only instances
• Use data volumes to take care of persistent data
Layers
Images are layered
• Docker store images in a layered file system
• Each instruction from Dockerfile is a distinct
read only layer
• When you create a new container, you add a
new, thin, writable layer
pull base image…
pull base image…
pull base image, done
build: add new layers
build: add new layers
build: add new layers
build: done
run container
Practice
Application
• We have a demo Django app written in Python 3
• We are going to serve static along with the app
• We don't care about HTTPS inside the container
• Logging and monitoring is out of the scope of
this talk
ls -la
• Dockerfile — build instructions
• .dockerignore — excludes files from the
build context
• demo — app source code
• etc — runtime configuration files
Dockerfile
Dockerfile: libs, bins
FROM ubuntu:16.04
RUN export DEBIAN_FRONTEND=noninteractive 
&& apt-get update -y && apt-get upgrade -y 
&& apt-get install -y nginx-light 
python3 python3-pip python3-psycopg2 
&& BUILD_DEPS='build-essential python3-dev' 
&& apt-get install -y ${BUILD_DEPS} 
&& pip3 install --no-cache-dir circus==0.13.0 gunicorn==19.5.0 
&& apt-get autoremove -y ${BUILD_DEPS} 
&& apt-get clean 
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Dockerfile best practices
• Join commands sequence into one RUN
instruction to reduce the number of
layers
• Clean build dependencies
• Plan your layers to take advantage of the
Docker build cache
Dockerfile: pip install
• Container is an isolated environment, so you
don't have to use python-virtualenv
• We do python packages installation in a
separate step to achieve caching
COPY requirements.txt /opt/demo/app/

RUN pip3 install --no-cache-dir 
-r /opt/demo/app/requirements.txt
Dockerfile: prepare the app
• Copy the app source code and configuration
files
• Fix files permissions
• Run validations (e.g. nginx -t)
• Execute management scripts to prepare the app
Dockerfile: prepare the app
COPY etc/ /etc/
COPY demo/ /opt/demo/app/
WORKDIR /opt/demo/app
ENV STATIC_ROOT=/opt/demo/static
RUN nginx -t 
&& ./manage.py collectstatic 
--settings=demo.settings --no-input -v0
CMD ["circusd", "/etc/circus/web.ini"]
etc
etc/circus/web.ini
[watcher:web]

cmd=/usr/local/bin/gunicorn 
demo.wsgi:application -c gunicorn.py

working_dir = /opt/demo/app

copy_env = True

user = www-data
[watcher:nginx]

cmd = /usr/sbin/nginx

stop_signal = QUIT

user = root
etc/nginx/sites-available/default
server {

listen 80;

location / {

include proxy_params;

proxy_pass http://127.0.0.1:8000;

}

location /static/ {

root /opt/demo/;

access_log off;

}

}
/etc/gunicorn.py
import multiprocessing

import os



bind = '127.0.0.1:8000'

default_workers = multiprocessing.cpu_count() * 2 + 1

workers = os.environ.get(
'WEB_CONCURRENCY', default_workers)

worker_class = 'sync'

max_requests = 300
max_requests_jitter = 300

errorlog = '-'
demo/settings.py
The best way to configure your app is
environment (e.g. database connection)
DATABASES = {

'default': dj_database_url.config(

env='DATABASE_URL',

default='postgres://localhost/demo')}
Demo
docker-compose.yml
web:
build: .
container_name: web
environment:
DJANGO_SETTINGS_MODULE: demo.settings_prod
DATABASE_URL: postgres://postgres:secret@db/demo
ALLOWED_HOSTS: "*"
ports:
- "80:80"
db:
image: postgres:9.5
environment:
POSTGRES_PASSWORD: "secret"
POSTGRES_DB: "demo"
volumes:
- /var/lib/postgresql/data
Build and run
We can build an image using docker-compose
docker-compose build
Run containers
docker-compose up -d
Run database migrations
docker exec -it web 

/opt/demo/app/manage.py migrate
Production
Docker Registry
• You can use any SaaS solution (e.g. Docker
Hub, Quay, Amazon ECR, Google Container
Registry)
• Or deploy and configure your own Registry, it's
easy and fully automated
Orchestration
• Docker Compose is a good choice for small projects
• You should automate your deployment with tools like
Ansible or have a look at Docker Swarm if you want
to manage a medium-sized cluster
• Kubernetes and Mesosphere are complex tools with
advanced features
• Alternatively you can use SaaS solutions like Docker
Cloud, Amazon ECS, Google Container Engine
Good luck!
Links
• Demo https://github.com/satyrius/paid
• Docs https://docs.docker.com/
• Best practices https://docs.docker.com/engine/
userguide/eng-image/dockerfile_best-practices/
• Circus https://circus.readthedocs.io/en/latest/for-ops/
configuration/
• Gunicorn http://docs.gunicorn.org/en/stable/
settings.html
Jobs
• ostrovok.ru is looking for Python/Golang/iOS/
Android developers and much more

https://jobs.lever.co/ostrovok.ru
• sabaka.io is looking for DevOps/SysOps
engineers and Python/Golang talents

https://angel.co/sabaka/jobs
Questions?
anton.egoroff@gmail.com

More Related Content

What's hot

GoLang Introduction
GoLang IntroductionGoLang Introduction
GoLang Introduction
Spandana Govindgari
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
Opersys inc.
 
Nginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptxNginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptx
wonyong hwang
 
Zabbix Performance Tuning
Zabbix Performance TuningZabbix Performance Tuning
Zabbix Performance Tuning
Ricardo Santos
 
Linux Troubleshooting
Linux TroubleshootingLinux Troubleshooting
Linux Troubleshooting
Keith Wright
 
Building aosp
Building aospBuilding aosp
Building aosp
gvercoutere
 
CNIT 121: 2 IR Management Handbook
CNIT 121: 2 IR Management HandbookCNIT 121: 2 IR Management Handbook
CNIT 121: 2 IR Management Handbook
Sam Bowne
 
Yocto Project introduction
Yocto Project introductionYocto Project introduction
Yocto Project introduction
Yi-Hsiu Hsu
 
Windows Registry
Windows RegistryWindows Registry
Windows Registry
primeteacher32
 
Linux Operating System
Linux Operating SystemLinux Operating System
Linux Operating System
KunalKewat1
 
Linux Binary Exploitation - Stack buffer overflow
Linux Binary Exploitation - Stack buffer overflowLinux Binary Exploitation - Stack buffer overflow
Linux Binary Exploitation - Stack buffer overflow
Angel Boy
 
Kernel Module Programming
Kernel Module ProgrammingKernel Module Programming
Kernel Module Programming
Saurabh Bangad
 
Provisión Automática de máquinas con Ansible
Provisión Automática de máquinas con AnsibleProvisión Automática de máquinas con Ansible
Provisión Automática de máquinas con Ansible
Carlos Gimeno Yáñez
 
Why you should care about Go (Golang)
Why you should care about Go (Golang)Why you should care about Go (Golang)
Why you should care about Go (Golang)
Aaron Schlesinger
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
Sergiu-Ioan Ungur
 
Linux architecture
Linux architectureLinux architecture
Linux architecturemcganesh
 
Compression
CompressionCompression
Compressionaswathyu
 
Introduction to the linux command line.pdf
Introduction to the linux command line.pdfIntroduction to the linux command line.pdf
Introduction to the linux command line.pdf
CesleySCruz
 
Embedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoEmbedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoSherif Mousa
 

What's hot (20)

GoLang Introduction
GoLang IntroductionGoLang Introduction
GoLang Introduction
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Nginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptxNginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptx
 
Zabbix Performance Tuning
Zabbix Performance TuningZabbix Performance Tuning
Zabbix Performance Tuning
 
Linux Troubleshooting
Linux TroubleshootingLinux Troubleshooting
Linux Troubleshooting
 
Building aosp
Building aospBuilding aosp
Building aosp
 
CNIT 121: 2 IR Management Handbook
CNIT 121: 2 IR Management HandbookCNIT 121: 2 IR Management Handbook
CNIT 121: 2 IR Management Handbook
 
Yocto Project introduction
Yocto Project introductionYocto Project introduction
Yocto Project introduction
 
Windows Registry
Windows RegistryWindows Registry
Windows Registry
 
Linux Operating System
Linux Operating SystemLinux Operating System
Linux Operating System
 
Linux Binary Exploitation - Stack buffer overflow
Linux Binary Exploitation - Stack buffer overflowLinux Binary Exploitation - Stack buffer overflow
Linux Binary Exploitation - Stack buffer overflow
 
Kernel Module Programming
Kernel Module ProgrammingKernel Module Programming
Kernel Module Programming
 
Provisión Automática de máquinas con Ansible
Provisión Automática de máquinas con AnsibleProvisión Automática de máquinas con Ansible
Provisión Automática de máquinas con Ansible
 
Why you should care about Go (Golang)
Why you should care about Go (Golang)Why you should care about Go (Golang)
Why you should care about Go (Golang)
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Compression
CompressionCompression
Compression
 
Introduction to the linux command line.pdf
Introduction to the linux command line.pdfIntroduction to the linux command line.pdf
Introduction to the linux command line.pdf
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Embedded Linux from Scratch to Yocto
Embedded Linux from Scratch to YoctoEmbedded Linux from Scratch to Yocto
Embedded Linux from Scratch to Yocto
 

Similar to Deliver Python Apps with Docker

CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day ThailandCI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
Troublemaker Khunpech
 
Docker module 1
Docker module 1Docker module 1
Docker module 1
Liang Bo
 
DevAssistant, Docker and You
DevAssistant, Docker and YouDevAssistant, Docker and You
DevAssistant, Docker and You
BalaBit
 
DCSF 19 Building Your Development Pipeline
DCSF 19 Building Your Development Pipeline  DCSF 19 Building Your Development Pipeline
DCSF 19 Building Your Development Pipeline
Docker, Inc.
 
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
Puppet
 
habitat at docker bud
habitat at docker budhabitat at docker bud
habitat at docker bud
Mandi Walls
 
Getting Started with Docker
Getting Started with DockerGetting Started with Docker
Getting Started with Docker
Geeta Vinnakota
 
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
Eric Smalling
 
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
Sencha
 
Docker presentation
Docker presentationDocker presentation
Docker presentation
Shankar Chaudhary
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2
Vincent Mercier
 
Run automated tests in Docker
Run automated tests in DockerRun automated tests in Docker
Run automated tests in Docker
Oleksandr Metelytsia
 
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios
 
Velocity NYC 2017: Building Resilient Microservices with Kubernetes, Docker, ...
Velocity NYC 2017: Building Resilient Microservices with Kubernetes, Docker, ...Velocity NYC 2017: Building Resilient Microservices with Kubernetes, Docker, ...
Velocity NYC 2017: Building Resilient Microservices with Kubernetes, Docker, ...
Ambassador Labs
 
DCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development PipelineDCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development Pipeline
Docker, Inc.
 
Docker engine - Indroduc
Docker engine - IndroducDocker engine - Indroduc
Docker engine - Indroduc
Al Gifari
 
[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101
Naukri.com
 
What's New in Docker - February 2017
What's New in Docker - February 2017What's New in Docker - February 2017
What's New in Docker - February 2017
Patrick Chanezon
 
Containerization using docker and its applications
Containerization using docker and its applicationsContainerization using docker and its applications
Containerization using docker and its applications
Puneet Kumar Bhatia (MBA, ITIL V3 Certified)
 

Similar to Deliver Python Apps with Docker (20)

CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day ThailandCI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
 
Docker module 1
Docker module 1Docker module 1
Docker module 1
 
DevAssistant, Docker and You
DevAssistant, Docker and YouDevAssistant, Docker and You
DevAssistant, Docker and You
 
DCSF 19 Building Your Development Pipeline
DCSF 19 Building Your Development Pipeline  DCSF 19 Building Your Development Pipeline
DCSF 19 Building Your Development Pipeline
 
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
PuppetConf 2017: What’s in the Box?!- Leveraging Puppet Enterprise & Docker- ...
 
habitat at docker bud
habitat at docker budhabitat at docker bud
habitat at docker bud
 
Getting Started with Docker
Getting Started with DockerGetting Started with Docker
Getting Started with Docker
 
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
 
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
 
Docker presentation
Docker presentationDocker presentation
Docker presentation
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2
 
Run automated tests in Docker
Run automated tests in DockerRun automated tests in Docker
Run automated tests in Docker
 
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
 
Velocity NYC 2017: Building Resilient Microservices with Kubernetes, Docker, ...
Velocity NYC 2017: Building Resilient Microservices with Kubernetes, Docker, ...Velocity NYC 2017: Building Resilient Microservices with Kubernetes, Docker, ...
Velocity NYC 2017: Building Resilient Microservices with Kubernetes, Docker, ...
 
DCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development PipelineDCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development Pipeline
 
Docker engine - Indroduc
Docker engine - IndroducDocker engine - Indroduc
Docker engine - Indroduc
 
[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101
 
What's New in Docker - February 2017
What's New in Docker - February 2017What's New in Docker - February 2017
What's New in Docker - February 2017
 
Containerization using docker and its applications
Containerization using docker and its applicationsContainerization using docker and its applications
Containerization using docker and its applications
 
Containerization using docker and its applications
Containerization using docker and its applicationsContainerization using docker and its applications
Containerization using docker and its applications
 

Recently uploaded

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 

Recently uploaded (20)

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 

Deliver Python Apps with Docker

  • 1. by Anton Egorov July 2016 Deliver Python Apps with Docker
  • 2. Who am I? • Software Engineer, 10 years in web development • Scripting mostly with Python • 2 years using Docker, dockerized about 50 apps, 80% of them were Python apps • Ex Lead Developer at ostrovok.ru • CTO and Founder at sabaka.io
  • 3. Plan • Quick introduction to Docker • App dockerization example • Production deployment notes • Treasure Goblin lives on special slides
  • 4. Docker in a few slides
  • 5. What is Docker? • It’s an open-source project that automates application deployment using containers • Initial release was in March 2013 • Written in Go • Works on Linux, OS X, Windows
  • 6. Why Docker? • The best tool for software packaging • Easy to build, just follow best practices • Fast at runtime, overhead is close to nothing • You have identical installation at any environment (dev, stage, prod) • Predictable, easy to test, makes QA happy
  • 7. Image • An image is a container basis • It’s a filesystem and a set of parameters to use at runtime (libs, bins, your software) • It doesn’t have a state and never changes • Dockerfile contains instructions to build the image
  • 8. Container • A container is a running instance of the image • It consists of • Docker image • Execution environment • Set of instructions
  • 9. Data Volume • Directory within one or more containers that bypasses the Union File System • Designed to persist data, independent of the container’s life cycle
  • 10. Notes • Treat containers as read-only instances • Use data volumes to take care of persistent data
  • 12. Images are layered • Docker store images in a layered file system • Each instruction from Dockerfile is a distinct read only layer • When you create a new container, you add a new, thin, writable layer
  • 16. build: add new layers
  • 17. build: add new layers
  • 18. build: add new layers
  • 22. Application • We have a demo Django app written in Python 3 • We are going to serve static along with the app • We don't care about HTTPS inside the container • Logging and monitoring is out of the scope of this talk
  • 23. ls -la • Dockerfile — build instructions • .dockerignore — excludes files from the build context • demo — app source code • etc — runtime configuration files
  • 25. Dockerfile: libs, bins FROM ubuntu:16.04 RUN export DEBIAN_FRONTEND=noninteractive && apt-get update -y && apt-get upgrade -y && apt-get install -y nginx-light python3 python3-pip python3-psycopg2 && BUILD_DEPS='build-essential python3-dev' && apt-get install -y ${BUILD_DEPS} && pip3 install --no-cache-dir circus==0.13.0 gunicorn==19.5.0 && apt-get autoremove -y ${BUILD_DEPS} && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
  • 26. Dockerfile best practices • Join commands sequence into one RUN instruction to reduce the number of layers • Clean build dependencies • Plan your layers to take advantage of the Docker build cache
  • 27. Dockerfile: pip install • Container is an isolated environment, so you don't have to use python-virtualenv • We do python packages installation in a separate step to achieve caching COPY requirements.txt /opt/demo/app/
 RUN pip3 install --no-cache-dir -r /opt/demo/app/requirements.txt
  • 28. Dockerfile: prepare the app • Copy the app source code and configuration files • Fix files permissions • Run validations (e.g. nginx -t) • Execute management scripts to prepare the app
  • 29. Dockerfile: prepare the app COPY etc/ /etc/ COPY demo/ /opt/demo/app/ WORKDIR /opt/demo/app ENV STATIC_ROOT=/opt/demo/static RUN nginx -t && ./manage.py collectstatic --settings=demo.settings --no-input -v0 CMD ["circusd", "/etc/circus/web.ini"]
  • 30. etc
  • 31. etc/circus/web.ini [watcher:web]
 cmd=/usr/local/bin/gunicorn demo.wsgi:application -c gunicorn.py
 working_dir = /opt/demo/app
 copy_env = True
 user = www-data [watcher:nginx]
 cmd = /usr/sbin/nginx
 stop_signal = QUIT
 user = root
  • 32. etc/nginx/sites-available/default server {
 listen 80;
 location / {
 include proxy_params;
 proxy_pass http://127.0.0.1:8000;
 }
 location /static/ {
 root /opt/demo/;
 access_log off;
 }
 }
  • 33. /etc/gunicorn.py import multiprocessing
 import os
 
 bind = '127.0.0.1:8000'
 default_workers = multiprocessing.cpu_count() * 2 + 1
 workers = os.environ.get( 'WEB_CONCURRENCY', default_workers)
 worker_class = 'sync'
 max_requests = 300 max_requests_jitter = 300
 errorlog = '-'
  • 34. demo/settings.py The best way to configure your app is environment (e.g. database connection) DATABASES = {
 'default': dj_database_url.config(
 env='DATABASE_URL',
 default='postgres://localhost/demo')}
  • 35. Demo
  • 36. docker-compose.yml web: build: . container_name: web environment: DJANGO_SETTINGS_MODULE: demo.settings_prod DATABASE_URL: postgres://postgres:secret@db/demo ALLOWED_HOSTS: "*" ports: - "80:80" db: image: postgres:9.5 environment: POSTGRES_PASSWORD: "secret" POSTGRES_DB: "demo" volumes: - /var/lib/postgresql/data
  • 37. Build and run We can build an image using docker-compose docker-compose build Run containers docker-compose up -d Run database migrations docker exec -it web 
 /opt/demo/app/manage.py migrate
  • 39. Docker Registry • You can use any SaaS solution (e.g. Docker Hub, Quay, Amazon ECR, Google Container Registry) • Or deploy and configure your own Registry, it's easy and fully automated
  • 40. Orchestration • Docker Compose is a good choice for small projects • You should automate your deployment with tools like Ansible or have a look at Docker Swarm if you want to manage a medium-sized cluster • Kubernetes and Mesosphere are complex tools with advanced features • Alternatively you can use SaaS solutions like Docker Cloud, Amazon ECS, Google Container Engine
  • 42. Links • Demo https://github.com/satyrius/paid • Docs https://docs.docker.com/ • Best practices https://docs.docker.com/engine/ userguide/eng-image/dockerfile_best-practices/ • Circus https://circus.readthedocs.io/en/latest/for-ops/ configuration/ • Gunicorn http://docs.gunicorn.org/en/stable/ settings.html
  • 43. Jobs • ostrovok.ru is looking for Python/Golang/iOS/ Android developers and much more
 https://jobs.lever.co/ostrovok.ru • sabaka.io is looking for DevOps/SysOps engineers and Python/Golang talents
 https://angel.co/sabaka/jobs