Building Python Web Apps with Docker

  • Published on
    12-Apr-2017

  • View
    1.217

  • Download
    0

Embed Size (px)

Transcript

  • Building PythonWeb Apps with

    Docker

    Mark Adams Bitbucket Developer Atlassian @markadams

    https://twitter.com/markadams

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

    A Python web app

    Docker Engine

    Docker Hub

    Docker Compose

    Docker Machine

  • What is

    ???

  • Traditional Virtual Machines

    APP A APP B

    LIBS LIBS

    GUEST OS GUEST OS

    HYPERVISOR

    HOST OS

    SERVER

    Robust

    Monolithic

    Slow toboot

    Heavy

  • Containers

    APP A APP B

    LIBS LIBS DOCKER

    HOST OS

    SERVER

    Lean

    Portable

    Lightweight

    Efficient

    Isolated

  • Where are containers useful?

  • Local Development

  • CI BuildsJenkins, Bamboo, etc.

  • Deploying to productionand scaling!

  • Where do I get it?

  • Windows & MacDocker Toolbox

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

  • Linux$wgetqOhttps://get.docker.com/|sh

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

  • Architecture

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

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

  • Docker EngineBuilds images and runs containers

    Dockerfile

    FROMpython:3.4

    EXPOSE8000WORKDIR/usr/src/app

    #InstalldependenciesCOPYrequirements.txtrequirements.txtRUNpipinstallrrequirements.txt

    #Copytherestoftheapplication'scodeCOPY./usr/src/app

    #RuntheappCMD["./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

  • Docker Hubhttp://hub.docker.com

    $dockerpullubuntu

    Usingdefaulttag:latestlatest:PullingfromubuntuDownloading10.8MB/158.6MBfec9fec2e960:Downloadcomplete9f834db6fd2c:DownloadcompleteDownloading5.7MB/30.2MBb13fbdab1f72:Downloadcomplete843e2bded498:Alreadyexists

    docker pushpushes to the repository

    docker pullpulls an image from the repository

    Public or Private

    http://hub.docker.com/

  • 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

  • Docker MachineProvisions and manages Docker hosts

    Works with

    amazonec2azuredigitaloceanexoscalegoogleopenstackrackspacesoftlayervirtualboxvmwarevcloudairvmwarevsphere

    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

  • Demo

    2:15

  • Orchestration!

  • Thank you!@markadams

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

    https://twitter.com/markadamshttps://bitbucket.org/markadams/pytexas-2015