Introduction to docker

43
Introduction to Docker Willy Kuo Feb 25, 2013

description

A brief introduction to docker. Demo: Run Bottle, a simple python web framework, in a docker container

Transcript of Introduction to docker

Page 1: Introduction to docker

Introduction to DockerWilly Kuo

Feb 25, 2013

Page 2: Introduction to docker

About Me• About me

• Work at numerinfo.com

• Organizor of http://www.meetup.com/Docker-Taipei/

• https://github.com/waitingkuo

[email protected]

Page 3: Introduction to docker

The Challenge

Page 4: Introduction to docker

The Matrix From Hell

Page 5: Introduction to docker

Cargo Transport Pre-1960

Page 6: Introduction to docker

The Matrix From Hell

Page 7: Introduction to docker

Solution: Intermodal Shipping Container

Page 8: Introduction to docker

Docker is a shipping container system for code

Page 9: Introduction to docker

Docker eliminates the matrix from hell

Page 10: Introduction to docker

Deploy to almost anywhere

OK Soon Soon ?

Page 11: Introduction to docker

VMs vs Containers

Page 12: Introduction to docker

VMs vs Containers

Page 13: Introduction to docker

Installation• Natively (Linux)

http://docs.docker.io/en/latest/installation/#installation-list

• Boot2Docker (Linux, OSX)https://github.com/boot2docker/boot2docker

• Vagrant https://github.com/waitingkuo/docker-vagrant

Page 14: Introduction to docker

Play Docker via Vagrant• Install vagrant & virtualbox

• $ git clone https://github.com/waitingkuo/docker-vagrant.git$ cd docker-vagrant$ vagrant up$ vagrant ssh

• Start to play docker

Page 15: Introduction to docker

Download a pre-built image

• $ docker pull ubuntu

• You can find more images here https://index.docker.io/

Page 16: Introduction to docker

Docker Images?

• $ docker images

Page 17: Introduction to docker

Run Something…

• $ docker run ubuntu echo hi

• $ docker run ubuntu uname -a

• $ docker run ubuntu ifconfig

Page 18: Introduction to docker

How about running bash?

• $ docker run ubuntu bash

• oops

• $ docker run -i -t ubuntu bash

Page 19: Introduction to docker

Let’s install something

• $ docker run ubuntu apt-get install -y python-pip

• Try to install something via pip

• $ docker run ubuntu pip install bottle

• Where’s my pip?

Page 20: Introduction to docker

docker ps• $ docker ps

• Nothing …

• $ docker -a

• Too much …

• $ docker ps -l

• That’s it

Page 21: Introduction to docker

Think about Git

• Coding…

• $ git add -A

• $ git commit -m ‘xxx’

Page 22: Introduction to docker

Commit!!?

• $ docker commit <container-id> mypip

• Now, you have a new image called mypip

• $ docker images

Page 23: Introduction to docker

Finally, you can use pip

• $ docker run mypip pip install bottle

• $ docker commit <container-id> mybottle

Page 24: Introduction to docker

Time to run a web server

• Run a simple website using bottle framework

• https://github.com/waitingkuo/bottle-sample

Page 25: Introduction to docker

Clone our project!

• First, we need git

• $ docker run mybottle apt-get install git-core

• uuuh… Seems we need to do apt-get update

Page 26: Introduction to docker

Apt-get update and install again

• $ docker run mybottle apt-get update

• $ docker commit <container-id> myupdate

• $ docker run myupdate apt-get install git-core

• $ docker commit <container-id> mygit

Page 27: Introduction to docker

Clone our project part 2

• $ docker run mygit git clone https://github.com/waitingkuo/bottle-sample.git

• docker commit <container-id> myweb

Page 28: Introduction to docker

Bottle Rock

• $ docker run myweb python bottle-sample/app.py

• htttp://192.168.66.66:8080 (192.168.66.66 is the ip for the virtual machine we create by vagrant)

• What the fuckrock??

Page 29: Introduction to docker

Port forwarding

• $ docker run -p 9999:8080 myweb python bottle-sample/app.py

Page 30: Introduction to docker

Daemonize?

• $ docker run -p 9999:8080 myweb python bottle-sample/app.py

• Now, our web server is running in the background

• $ docker ps

Page 31: Introduction to docker

Can we kill it?

• just like the kill command, except that we should assign the container id instead of pid

• $ docker kill <container-id>

Page 32: Introduction to docker

Dockerfile

• Tutorial: https://www.docker.io/learn/dockerfile/

Page 33: Introduction to docker

Example• DockerfileFROM ubuntu RUN apt-get update RUN apt-get install -y git-core RUN apt-get install -y python-pip RUN pip install bottle RUN git clone https://github.com/waitingkuo/bottle-sample.git CMD python bottle-sample/app.py

Page 34: Introduction to docker

Build image by Dockerfile

• $ docker built -t myweb-2 . # don’t forget the .

• Now, you have a new image, myweb-2

• $ docker image

• $ docker run -p 9999:8080 myweb-2 python bottle-sample/app.py

Page 35: Introduction to docker

Think about GitHub

• We have already had docker commit

• Can I push my image to something like GitHub?

Page 36: Introduction to docker

Docker Index

• https://index.docker.io/

• The place to find Docker container images

• Can automatically create Docker Image from your project on Github, and keep them in sync

Page 37: Introduction to docker

The basics of the Docker System

Page 38: Introduction to docker

Changes & Updates

Page 39: Introduction to docker

Example - Deploy Mongodb

• https://index.docker.io/u/waitingkuo/mongodb/

• The Dockfile is hosted on Github https://github.com/waitingkuo/dockerfiles/blob/master/dockerfiles/mongodb/Dockerfile

• $ docker run -d -p 27017:27017 -p 28017:28017 waitingkuo/mongodb

• Mongodb is runninghttp://192.168.66.66:28017/

Page 40: Introduction to docker

Ecosystem - WebUI

• dockeruihttps://github.com/crosbymichael/dockerui

• Shipyardhttps://github.com/shipyard/shipyard

Page 41: Introduction to docker

Ecosystem - PaaS

• deishttps://github.com/opdemand/deis

• dokkuhttps://github.com/progrium/dokku

• flynnhttps://flynn.io/

Page 42: Introduction to docker

Ecosystem - CI

• dronehttps://github.com/drone/drone

• StriderCDhttp://stridercd.com/

Page 43: Introduction to docker

Thank you!