Develop with docker 2014 aug

42
Develop with Docker Local development powered by Docker – August 2014 Slides prepared by Vincent De Smet – Art ripped from docker.com & tutum.co

Transcript of Develop with docker 2014 aug

Develop with Docker

Local development powered by Docker – August 2014

Slides prepared by Vincent De Smet – Art ripped from docker.com & tutum.co

Target: Quick setup

Install+SetupBoot2Docker

Clone Git repos

Run Containers

Docker Intro

A quick intro to Linux Containers & Docker

based on IDF2014 presentation by Nicholas Weaver

Why containers

VM

Linux OS

library

Service1

VM

Linux OS

library

Service2

VM

Linux OS

library

Service2

Why containers

Linux OS

library

Service1 Service2 Service3

Container A Container B Container C

Why containers

Faster lifecycle vs virtual machines

Contains what is running within the OS

Ideal for homogenous application stacks

on Linux

Almost non-existent overhead

More complex to configure

Security isolation needs improvement

Only Linux support at the moment

Docker core concept - Images

Ordered results of actions to build a container

Add file / open port / run a command

DevOps-like source code for a deployment of an image

Uses a copy-on-write file system

Docker core concepts

Docker image

Ability to build your own images based on existing images (Dockerfile)

Ability to share images (on the hub / registry)

Docker container = running instance of an image

Ability to tag and reuse

Image is copied on write, original tag is not updated

Ability to link containers (Docker sets up network between them)

Ability to mount persistent storage called volumes

It is recommended to define data volume containers

Docker Image

Images are layers

bootfs

rootfs

from debian:jessie

run apt-get

set env var

cmd = “python”

python

Docker Image

Images are layers

bootfs

rootfs

from debian:jessie

run apt-get

set env var

cmd = “python”

my_app

Docker Image

Images are layers

bootfs

rootfs

from python

add app.py

mount dir

cmd = “./app.py”

Docker Image

Images are layers

Image Registry

Public Docker registry: Docker Hub

In-house registry (open source / self host)

Docker Hub

Client - Server

Linux / OS X / Windows

Docker Client

Linux

Docker Daemon

Client - Server

Linux / OS X / Windows

Docker Client

Linux

Docker Daemon[docker run backend]

backend

Image

Container

Client - Server

Linux / OS X / Windows

Docker Client

Linux

Docker Daemon[docker run frontend]

backend

Image

Container

frontend

Image

Container

Client - Server

Linux / OS X / Windows

Docker Client

Linux

Docker Daemon[docker stop frontend]

backend

Image

Container

frontend

Image

Container

Client - Server

Linux / OS X / Windows

Docker Client

Linux

Docker Daemon

backend

Image

Container

Developing in containers

making containers your home

Production config requirements

Stable

Use production approved methodologies

Code is fixed / baked in

Secure

No code leak / debug info

Run according to least privilege principle

Speed / Scalable

Performance settings enabled

Multiple backend worker processes

Proxy: Caching

Proxy: Backend cluster + load balancing

Lean

No junk

Development config requirements

Code is flexible

Interactive code editing (live reload)

Full debug & tracing capabilities

Code Management Tools

Frontend: packaging / build tools – node cli

Backend: django / sqllite – Python cli

Development setup

nodejs python

angularjsgruntjs watch

django./manage.py runserver

localdocker:9000

static html + javascript + livereload

localdocker:9000/api

proxy - requestjson response

LOCAL VM

frontendcli backendcli

:8080http protocol

Production setup

nginx uWSGI

angularjsstatic html

djangorest api

mysamplewebsite.com

static html + javascript

mysamplewebsite.com/api

proxy - requestjson response

SERVER / LOCAL VM

frontend backend

:8000uwsgi protocol

How did I choose my images

Search environment requirements

Filter down to common base image (Debian)

Filter down to best practice

no phusion based for me

Production images

backend image – from python:3

backend/src read only /usr/scr/app

volumes/db read/write /etc/data/

port 8000 uwsgi

user: www-data

frontend image – from nginx

frontend/dist read only /usr/local/nginx/html

port 80 http

user root

Development images

backendcli image – from: python:3

backend/src read/write /usr/scr/app

volumes/db read/write /etc/data/

port 8080 http

user root

frontendcli image – from: nodejs

frontend/src read/write /usr/src/app

port 9000 http

user yeoman

Setup boot2docker VM

docs.docker.com for installation instructions

Set up samba shares & utilities

https://gist.github.com/so0k/d4f5e485a81ca5768643

Bash management script I wrote

https://gist.github.com/so0k/b73248e7e42a0e4fd564

Management script

setup / teardown

backendcli [name] / frontendcli

build <cli|prod>

start / stop

enter <name>

cleanup

setup / teardown

setup / teardown initial data containers (+chmod)

build demo

Build cli to start development

backendcli demo

Use python environment for DRF backend:

Start a new django application REST API for task app

Sync db

Generate model graph

frontendcli demo

Use generator-angular to start demo project

Use yo to generate angular project directory

Use bower to install application dependencies

Use npm to install grunt-proxy

Modify gruntfile to run grunt-proxy to backend

Use grunt for editing with live reload

Use grunt to package the app for production

enter demo

Enter backend to

See open connections

Run dbshell to review tables created

cleanup

Clean up images without a tag:

build & cleanup

Once images are built & cleaned up:

Run production

Build prod containers

Start / stop production containers

20 September 2014 – ToDo (long term):

Add environment variables for production containers

i.e.: to control settings.py (debug / ..)

Log management & performance monitoring (+orchestration)

Set up squid proxies to overcome slow internet builds

Target: CI

Push Code

Build Image

Run Containers

Architecture?

localdocker localdocker

Docker

hostgitlab

registry

Cloud hosting

on premise

QA testing

production

env

stageing

env

About me

Author: Vincent De Smet

this presentation source code:https://gist.github.com/so0k/b73248e7e42a0e4fd564

Presentation prepared for Docker Saigon Meetup Group

You can find us at:

http://www.meetup.com/Docker-Saigon

www.docker.com