Transcript
Page 1: Building Python Web Apps with Docker

Building PythonWeb Apps with

Docker

Mark Adams • Bitbucket Developer • Atlassian • @markadams

Page 2: Building Python Web Apps with Docker

What we'll cover (hopefully)What is Docker?

A Python web app

Docker Engine

Docker Hub

Docker Compose

Docker Machine

Page 3: Building Python Web Apps with Docker

What is

???

Page 4: Building Python Web Apps with Docker

Traditional Virtual Machines

APP A APP B

LIBS LIBS

GUEST OS GUEST OS

HYPERVISOR

HOST OS

SERVER

Robust

Monolithic

Slow toboot

Heavy

Page 5: Building Python Web Apps with Docker

Containers

APP A APP B

LIBS LIBS DOCKER

 

 

HOST OS

SERVER

Lean

Portable

Lightweight

Efficient

Isolated

Page 6: Building Python Web Apps with Docker

Where are containers useful?

Page 7: Building Python Web Apps with Docker
Page 8: Building Python Web Apps with Docker
Page 9: Building Python Web Apps with Docker
Page 10: Building Python Web Apps with Docker

Local Development

Page 11: Building Python Web Apps with Docker

CI BuildsJenkins, Bamboo, etc.

Page 12: Building Python Web Apps with Docker

Deploying to productionand scaling!

Page 13: Building Python Web Apps with Docker
Page 14: Building Python Web Apps with Docker

Where do I get it?

Page 15: Building Python Web Apps with Docker

Windows & MacDocker Toolbox

Installs Docker Client, Engine, Compose, Machine, Kitematic, and Virtualbox

Page 16: Building Python Web Apps with Docker

Linux$ wget ­qO­ https://get.docker.com/ | sh

Downloads a shell script to install the right package for your system

Page 17: Building Python Web Apps with Docker

Architecture

Page 18: Building Python Web Apps with Docker

Demo App!https://bitbucket.org/markadams/pytexas-2015-demo

Page 19: Building Python Web Apps with Docker

Docker EngineBuilds images and runs containers

Dockerfile

FROM python:3.4

EXPOSE 8000WORKDIR /usr/src/app

# Install dependenciesCOPY requirements.txt requirements.txtRUN pip install ­r requirements.txt

# Copy the rest of the application's codeCOPY . /usr/src/app

# Run the appCMD ["./run_app.sh"]

docker buildbuilds an image

docker runcreates a container from an image and runs it

docker logsshows the logs from a container

docker psshows what's running

Page 20: Building Python Web Apps with Docker

Docker Hubhttp://hub.docker.com

$ docker pull ubuntu

Using default tag: latestlatest: Pulling from ubuntuDownloading  10.8 MB/158.6 MBfec9fec2e960: Download complete9f834db6fd2c: Download completeDownloading  5.7 MB/30.2 MBb13fbdab1f72: Download complete843e2bded498: Already exists

docker pushpushes to the repository

docker pullpulls an image from the repository

Public or Private

Page 21: Building Python Web Apps with Docker

Docker ComposeDescribes the components of an application

YML Config

web:    build: .    links:        ­ 'db'    ports:        ­ '8000:8000'    environment:        ­ 'DATABASE_HOST=db'        ­ 'DATABASE_NAME=postgres'        ­ 'DATABASE_USER=postgres'        ­ 'DATABASE_PASSWORD=postgres'db:    image: postgres:9.4

docker-compose upstarts all the containers

docker-composebuildrebuilds your images

docker-compose stopstopps the containers

Page 22: Building Python Web Apps with Docker

Docker MachineProvisions and manages Docker hosts

Works with

    ­ amazonec2    ­ azure    ­ digitalocean    ­ exoscale    ­ google    ­ openstack    ­ rackspace    ­ softlayer    ­ virtualbox    ­ vmwarevcloudair    ­ vmwarevsphere             

docker-machine createcreates a new Docker host

docker-machine sshconnects to the host using SSH

docker-machine rmdestroys the host

docker-machine envsets environment variables for your client to

connect to the host

Page 23: Building Python Web Apps with Docker

Demo

2:15

Page 24: Building Python Web Apps with Docker

Orchestration!

Page 25: Building Python Web Apps with Docker

Thank you!@markadams

https://bitbucket.org/markadams/pytexas-2015