Introduction to docker

66
Introduce to

description

 

Transcript of Introduction to docker

Page 1: Introduction to docker

Introduce to

Page 2: Introduction to docker

Outline

What is docker?

Why docker?

Dockerfile

Page 3: Introduction to docker

What is docker?

An open platform for developing, shipping, and running applications

Page 4: Introduction to docker

What it want to solve?

Page 5: Introduction to docker

The matrix from hell

“You've got all types of servers, all types of different languages and frameworks, and all types of application versions to try and maintain across those platforms” - Ben Golub, CEO of Docker

Page 6: Introduction to docker

The matrix from hell

Page 7: Introduction to docker

We need a container

Page 8: Introduction to docker

The matrix from hell

Page 9: Introduction to docker

The matrix from hell

Page 10: Introduction to docker

Installation

Page 11: Introduction to docker

From ubuntu mainstream

Docker goes into Ubuntu mainstream since 14.04

Currently, v0.9

apt-get install docker.io

Page 12: Introduction to docker

From Official Repo

The latest version: v1.0

echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9

apt-get update

apt-get install lxc-docker

Page 13: Introduction to docker

Why Docker?

Page 14: Introduction to docker

Fast and less overhead

Image versioning

Portable

Page 15: Introduction to docker

Fast and less overhead

Page 16: Introduction to docker

VM v.s. Docker

Page 17: Introduction to docker

VM v.s. Docker

Server

Host OS

Page 18: Introduction to docker

VM v.s. Docker

Server

Host OS

Hypervisor

Page 19: Introduction to docker

VM v.s. Docker

Server

Host OS

VM VM

Hypervisor

Page 20: Introduction to docker

VM v.s. Docker

Server

Host OS

VM VM

Guest OS

Hypervisor

Page 21: Introduction to docker

VM v.s. Docker

Server

Host OS

VM VM

Guest OS

Hypervisor

Dep.

Page 22: Introduction to docker

VM v.s. Docker

Server

Host OS

VM VM

Guest OS

Hypervisor

Dep.

App

Page 23: Introduction to docker

VM v.s. Docker

Server

Host OS

VM VM

Guest OS

Hypervisor

Dep.

App

Server

Host OS

Page 24: Introduction to docker

VM v.s. Docker

Server

Host OS

VM VM

Guest OS

Hypervisor

Dep.

App

Server

Host OS

Docker Engine

Page 25: Introduction to docker

VM v.s. Docker

Server

Host OS

VM VM

Guest OS

Hypervisor

Dep.

App

Server

Host OS

Container Container

Docker Engine

Page 26: Introduction to docker

VM v.s. Docker

Server

Host OS

VM VM

Guest OS

Hypervisor

Dep.

App

Server

Host OS

Container Container

Docker Engine

Image1

Page 27: Introduction to docker

VM v.s. Docker

Server

Host OS

VM VM

Guest OS

Hypervisor

Dep.

App

Server

Host OS

Container Container

Docker Engine

Image1

Image2

Page 28: Introduction to docker

VM v.s. Docker

Server

Host OS

VM VM

Guest OS

Hypervisor

Dep.

App

Server

Host OS

Container Container

Docker Engine

Image1

App1

Image2

Page 29: Introduction to docker

VM v.s. Docker

Server

Host OS

VM VM

Guest OS

Hypervisor

Dep.

App

Server

Host OS

Container Container

Docker Engine

Image1

App1

Image2

App2

Page 30: Introduction to docker

VM v.s. Docker

Server

Host OS

VM VM

Guest OS

Hypervisor

Dep.

App

Server

Host OS

Container Container

Docker Engine

Image1

App1

Image2

App2

App3

Page 31: Introduction to docker

Live Demo

IP: 10.10.100.108

Username: test

Password: 123456

Page 32: Introduction to docker

docker pull

Download image from Docker Hub

docker pull [image]

Ex: docker pull debian

Page 33: Introduction to docker

docker run (1)

docker run [image] [command]

-i interactive mode

-t pseudo-tty

Ex: docker -i -t run debian /bin/bash

Page 34: Introduction to docker

Image versioning

Page 35: Introduction to docker

Image v.s. Container

Base on LXC and AUFS

Images are read-only

Read / write on container

Files in container won’t keep unless you commit

Page 36: Introduction to docker

Image v.s. Container

Base on LXC and AUFS

Images are read-only

Read and write on container

Files in container won’t keep unless you commit

Page 37: Introduction to docker

Image v.s. Container

docker pull debian

Page 38: Introduction to docker

Image v.s. Container

docker pull debian

docker run debian /bin/bash

Page 39: Introduction to docker

docker commit

docker commit [Container ID] [image name]

docker commit 1c1f5 new_image

Page 40: Introduction to docker

Image v.s. Container

docker pull debian

docker run debian /bin/bash

Page 41: Introduction to docker

Image v.s. Container

docker pull debian

docker commitdocker commit

docker run debian /bin/bash

Page 42: Introduction to docker

Image v.s. Container

docker pull debian

docker commitdocker commit

docker run debian /bin/bash

Page 43: Introduction to docker

Portable

Runs on all major Linux distributions

Boot2docker for Mac and Windows users

A ~25 MB tiny VM inside

Page 44: Introduction to docker

Ship your container

There are three ways to ship your container:

Docker Hub (docker push)

docker save

docker export

Page 45: Introduction to docker

docker save / load

This packing will preserve the history of a docker

docker save [Image Name] > [Archive Name]

docker load < [Archive Name]

Page 46: Introduction to docker

docker export / import

This way only keep the difference

docker export [Container ID] > [Archive Name]

cat [Archive Name] | docker import - [Image Name[:Tag]]

Page 47: Introduction to docker

Separation of Data and App

Page 48: Introduction to docker

docker run (2)

-v [host directory]:[container directory]Bind mount a volume

-p [host port]:[container port]Publish a container's port to the host

Page 49: Introduction to docker

Other useful command

docker ps

docker images

docker kill

docker rm

docker rmi

docker logs

docker inspect

Page 50: Introduction to docker

Dockerfile

Page 51: Introduction to docker

Syntax

FROM

RUN

ENV

ADD

VOLUME

EXPOSE

CMD

Page 52: Introduction to docker

Example

Page 53: Introduction to docker

docker build

docker build -t [Image Name[:Tag]]\<path to Dockerfile>

docker build -t my_image:v1 .

Page 54: Introduction to docker

Build once, run anywhere

Page 55: Introduction to docker

Examples

Page 56: Introduction to docker

My Concern

Easy to setup over a VM

Separate data and application

Reproduce my environment fast

Page 57: Introduction to docker

Jenkins

Initialize shared volume before service start

Use supervisor to manage multiple services

Page 58: Introduction to docker

One-time script

Page 59: Introduction to docker

Can not use upstart

Page 60: Introduction to docker

Use supervisor

Page 61: Introduction to docker

Summarize

Page 62: Introduction to docker

Do one thing at a time

Treat a docker container as an app

Page 63: Introduction to docker

Ecosystem

CoreOS - Work with SystemD

Openstack - An instance type

Docker Hub (Docker Index)

Many providers- Digital Ocean, EC2, Linode, Google Cloud Platform

Page 64: Introduction to docker

Gotcha

Don’t have its /sbin/init (Issue 1024)

Share kernel, can not run different Linux Kernel at a time

Use --privileged if needed

Page 65: Introduction to docker

Not mentioned

Link to another container

Use share volume on another container

Page 66: Introduction to docker

Q & A