future of development and deployment using docker

41
Tamer M Abdul-Radi @tabdulradi Eslam ElHusseiny @EslamElHusseiny https://github.com/kiosk12

Upload: tamer-radi

Post on 19-Jul-2015

383 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: Future of Development and Deployment using Docker

Tamer M Abdul-Radi @tabdulradi Eslam ElHusseiny @EslamElHusseiny https://github.com/kiosk12

Page 2: Future of Development and Deployment using Docker

Agenda

• Pain - What/Why Docker

• Developing and deploying a Django App

• How Docker works

Page 3: Future of Development and Deployment using Docker

–Every developer

“But it works on my machine.”

Page 4: Future of Development and Deployment using Docker

Django ? ? ? ? ?

PostgreSQL ? ? ? ? ?

Redis ? ? ? ? ?

Hadoop ? ? ? ? ?

Message Queue ? ? ? ? ?

Developer Laptop

QA Laptop

Staging Server

Production Server

Cloud

Matrix from Hell

Page 5: Future of Development and Deployment using Docker

(Pain) = n * m

• Every developer wastes almost a day to configure his machine

• What about tester’s machine?

• Hot patches during release nights!

n = size of team + staging + production m = size of project

Page 6: Future of Development and Deployment using Docker
Page 7: Future of Development and Deployment using Docker
Page 8: Future of Development and Deployment using Docker
Page 9: Future of Development and Deployment using Docker

Matrix from Hell!Django ? ? ? ?

PostgreSQL ? ? ? ? ?

Redis ? ? ? ? ?

Big Data ? ? ? ? ?

Message Queue ? ? ? ? ?

Developer Laptop

QA Laptop

Staging Server

Prod. on Server

Prod. on Cloud

Page 10: Future of Development and Deployment using Docker

Code time!Let’s get our hands dirty

Page 11: Future of Development and Deployment using Docker

Installation$ sudo apt-get install docker.io$ sudo pip install -U fig

For OSX and Windows: check “boot2docker”

Page 12: Future of Development and Deployment using Docker

Create DockerfileFROM python:2.7 ENV PYTHONUNBUFFERED 1 RUN mkdir /code WORKDIR /code ADD requirements.txt /code/ RUN pip install -r requirements.txt ADD . /code/

Page 13: Future of Development and Deployment using Docker

Create requirements.txt

django psycopg2

Page 14: Future of Development and Deployment using Docker

Create fig.ymldb:

image: postgres web:

build: . command: python manage.py runserverv 0.0.0.0:8000 volumes:

- ./code ports:

- “8000:8000” links:

- db

Page 15: Future of Development and Deployment using Docker

Start Django project

$ fig run web django-admin.py startproject example .$ lsDockerfile example fig.yml manage.py requirements.txt$ ls example__init__.py settings.py urls.py wsgi.py

Page 16: Future of Development and Deployment using Docker

Configure Django AppDATABASES = {

‘default’: { ‘ENGINE’: ‘django.db.backends.postgresql_psycopg2’, ‘NAME’: ‘postgres’, ‘USER’: ‘postgres’, ‘HOST’: ‘db’, ‘PORT’: 5432

} }

Page 17: Future of Development and Deployment using Docker

Run the app

$ fig up

Page 18: Future of Development and Deployment using Docker

In your browser

Page 19: Future of Development and Deployment using Docker

Access containers

$ fig run web ping db$ fig run web cat /etc/hosts

Page 20: Future of Development and Deployment using Docker

Polls App• Lets’s steal the polls app from official django tutorial

• https://docs.djangoproject.com/en/1.7/intro/tutorial01/

• Don’t forget to add polls to installed apps

$ fig run web python manage.py startapp polls

Page 21: Future of Development and Deployment using Docker

polls/models.pyfrom django.db import models

class Question(models.Model): question_text = models.CharField(max_length=200) pub_date = models.DateTimeField('date published')

class Choice(models.Model): question = models.ForeignKey(Question) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0)

Page 22: Future of Development and Deployment using Docker

polls/admin.py

from django.contrib import adminfrom polls.models import Question

admin.site.register(Question)

Page 23: Future of Development and Deployment using Docker

Polls App

$ fig run web python manage.py makemigrations polls$ fig run web python manage.py sqlmigrate polls 0001$ fig run web python manage.py sqlmigrate polls 0001

Page 24: Future of Development and Deployment using Docker

Running the app

#!/bin/sh

python manage.py migrate python manage.py runserver 0.0.0.0:8000

• Running the app became a bit more complex • We need to make sure that models are migrated • create run_web.sh

Page 25: Future of Development and Deployment using Docker

Update fig.ymldb:

image: postgres web:

build: . command: ./run_web.sh volumes:

- ./code ports:

- “8000:8000” links:

- db

Page 26: Future of Development and Deployment using Docker

Create admin account

$ fig run web python manage.py createsuperuser

Page 27: Future of Development and Deployment using Docker

In your browser

Page 28: Future of Development and Deployment using Docker

Deploy time!

Page 29: Future of Development and Deployment using Docker

Fig for productiondb:

image: postgres web:

build: . command: ./run_web.shvolumes:

- ./code ports:

- “80:8000” links:

- db

Page 30: Future of Development and Deployment using Docker

Create Amazon Machine

aws ec2 run-instances —image-id ami-234ecc54 —security-groups default —instance-type c4.large

—key-name kiosk12

Page 31: Future of Development and Deployment using Docker

Configure Amazon Machine

• sudo apt-get install docker.io

• sudo pip install -U fig

Page 32: Future of Development and Deployment using Docker

Run

• -d = Daemon mode

• -f = Specify fig file

$ fig up -d -f fig-production.yml

Page 33: Future of Development and Deployment using Docker

Docker Internals• Images

• Read-only templates

• Clone of the system with installed apps + code

• Containers

• Running instance of an image

• Isolated file system and ports

• Registeres

• Host for Images

• Dockerhub,com

Page 34: Future of Development and Deployment using Docker

Containers vs VM

Page 35: Future of Development and Deployment using Docker

Architecture

Page 36: Future of Development and Deployment using Docker

New Docker Features

Page 37: Future of Development and Deployment using Docker

Docker Machine

$ docker-machine create -d virtualbox dev$ docker-machine create -d digitalocean --

digitalocean-access-token=... staging$ docker-machine lsNAME ACTIVE DRIVER STATE URL dev virtualbox Running tcp://192.168.99.108:2376 staging * digitalocean Running tcp://104.236.37.134:2376

Page 38: Future of Development and Deployment using Docker

Docker Swarm

• Clustering for Dockerized distributed apps

• Selects a docker demon for your containers (created by Docker machine)

Page 39: Future of Development and Deployment using Docker

Docker Compose

• Docker bought fig!

• No need to install two tools in future

• Almost same yaml syntax

Page 40: Future of Development and Deployment using Docker

Fun with Docker• Explore dockerized apps at dockerhub.com with no

installation hassle!

• docker run mongo

• docker run --rm -v "$PWD" -p 4000:4000 grahamc/jekyll

• docker run -it --rm williamyeh/scala

• Some cool aliases here: http://github.com/tabdulradi/docker-fish-functions

Page 41: Future of Development and Deployment using Docker

Tamer M Abdul-Radi Software Engineer

twitter.com/tabdulradi github.com/tabdulradi

abdulradi.com

Thanks

Eslam ElHusseiny Systems Engineer twitter.com/EslamElHusseinygithub.com/EslamElHusseiny eslamelhusseiny.wordpress.com

http://github.com/Kiosk12/docker-django-demo