61

Containers, Docker, and Microservices: the Terrific Trio

Embed Size (px)

DESCRIPTION

One of the upsides of Microservices is the ability to deploy often,at arbitrary schedules, and independently of other services, instead of requiring synchronized deployments happening on a fixed time. But to really leverage this advantage, we need fast, efficient, and reliable deployment processes. That's one of the value propositions of Containers in general, and Docker in particular. Docker offers a new, lightweight approach to application portability.It can build applications using easy-to-write, repeatable, efficient recipes; then it can ship them across environments using a common container format; and it can run them within isolated namespaces which abstract the operating environment, independently of the distribution,versions, network setup, and other details of this environment. But Docker can do way more than deploy your apps. Docker also enables you to generalize Microservices principles and apply them on operational tasks like logging, remote access, backups, and troubleshooting.This decoupling results in independent, smaller, simpler moving parts.

Citation preview

Page 1: Containers, Docker, and Microservices: the Terrific Trio
Page 2: Containers, Docker, and Microservices: the Terrific Trio

Containers, Docker, and

Microservices

Page 3: Containers, Docker, and Microservices: the Terrific Trio

Jérôme Petazzoni(@jpetazzo)

Grumpy French DevOps- Go away or I will replace you

with a very small shell script

Runs everything in containers- Docker-in-Docker

- VPN-in-Docker

- KVM-in-Docker

- Xorg-in-Docker

- ...

Page 4: Containers, Docker, and Microservices: the Terrific Trio

Jérôme Petazzoni(@jpetazzo)

Built and scaled dotCloudPAAS with 106 services(I counted them!)- some examples: hosts, nats,

containers, builds, snapshots,metrics, billing, user permissions,infrastructure management, logs, ...

Page 5: Containers, Docker, and Microservices: the Terrific Trio
Page 6: Containers, Docker, and Microservices: the Terrific Trio

outline

Page 7: Containers, Docker, and Microservices: the Terrific Trio

Outline

Why microservices?What's the challenge?How does Docker help?Getting started with stacks of containers

Page 8: Containers, Docker, and Microservices: the Terrific Trio

why microservices

Page 9: Containers, Docker, and Microservices: the Terrific Trio

What is a microservice architecture?

Break big application down into many small servicesExample: e-commerce- web front-end

- catalog of products

- inventory/stock management

- shipping calculator

- payment processor

- billing/invoicing

- recommendation engine

- user profiles

Page 10: Containers, Docker, and Microservices: the Terrific Trio

Why is this useful?

Use different stacks for different services(can be seen as both good and bad!)

Replace (e.g. refactor) individual services easily(service boundary enforces API separation)

Decouples deployment; requires less coordination(deploy early, deploy often; more agility)

Helps implementing Jeff Bezos' “two-pizza rule”(many small teams overperform a single big team)

More effective “ownership” of services

Page 11: Containers, Docker, and Microservices: the Terrific Trio

what's the challenge?

Page 12: Containers, Docker, and Microservices: the Terrific Trio
Page 13: Containers, Docker, and Microservices: the Terrific Trio

Issues we will not address today

Fast, efficient RPC calls- ZeroRPC

- Cap'n Proto

- XMLRPC

- SOAP

- Dnode

- REST

- Queues (like AMQP), for long-running/async operations

Page 14: Containers, Docker, and Microservices: the Terrific Trio

Issues we will not address today

How to break application down in small parts- this is not always easy

- try to get help from people who have already done it

- but: it helps to achieve a better architecture (I promise)

Page 15: Containers, Docker, and Microservices: the Terrific Trio

Issues we could address today

Our app is now spread across multiple servicesThose services might (will) end up on many machinesSome of those services might (will) be scaled outConsequences:- our services will have to discover each other's location

- we will have to learn about load balancing

Page 16: Containers, Docker, and Microservices: the Terrific Trio

Issues we will address today

We're deploying 42 microservices instead of 1 appWe want to be able to deploy oftenObvious consequence: our deploy process must rock- it must be fast

- it must be reliable

- it must be automated

Page 17: Containers, Docker, and Microservices: the Terrific Trio

how does Docker help?

Page 18: Containers, Docker, and Microservices: the Terrific Trio

the big picture

Page 19: Containers, Docker, and Microservices: the Terrific Trio

Docker's mission

build, ship, and run any application, anywhere

Page 20: Containers, Docker, and Microservices: the Terrific Trio

Say again?

Build: package your application in a containerShip: move that container from a machine to anotherRun: execute that container (i.e. your application)Any application: anything that runs on LinuxAnywhere: local VM, cloud instance, bare metal...

Page 21: Containers, Docker, and Microservices: the Terrific Trio

build

Page 22: Containers, Docker, and Microservices: the Terrific Trio

Dockerfile

FROM ubuntu:14.04MAINTAINER Docker Team <[email protected]>

RUN apt-get updateRUN apt-get install -y nginxRUN echo 'Hi, I am in your container' \ >/usr/share/nginx/html/index.html

CMD [ "nginx", "-g", "daemon off;" ]

EXPOSE 80

Page 23: Containers, Docker, and Microservices: the Terrific Trio
Page 24: Containers, Docker, and Microservices: the Terrific Trio

ship

Page 25: Containers, Docker, and Microservices: the Terrific Trio

Docker Hub

Image name should be <username>/<reponame>e.g.: jpetazzo/web

docker pushdocker pull

Page 26: Containers, Docker, and Microservices: the Terrific Trio
Page 27: Containers, Docker, and Microservices: the Terrific Trio

Docker Hub

Image name should be <username>/<reponame>e.g.: jpetazzo/web

docker pushdocker pullIt's magic!

Page 28: Containers, Docker, and Microservices: the Terrific Trio
Page 29: Containers, Docker, and Microservices: the Terrific Trio

run

Page 30: Containers, Docker, and Microservices: the Terrific Trio

Execution is fast and lightweight

Let's look at a few benchmarks

Page 31: Containers, Docker, and Microservices: the Terrific Trio

Benchmark: container creation

$ time docker run ubuntu echo hello worldhello worldreal 0m0.258s

Disk usage: less than 100 kBMemory usage: less than 1.5 MB

Page 32: Containers, Docker, and Microservices: the Terrific Trio

Benchmark: infiniband

Page 33: Containers, Docker, and Microservices: the Terrific Trio

Benchmark: boot OpenStack instances

Page 34: Containers, Docker, and Microservices: the Terrific Trio

Benchmark: memory speed

Page 35: Containers, Docker, and Microservices: the Terrific Trio
Page 36: Containers, Docker, and Microservices: the Terrific Trio

Let's start a few containers

Just for run. Eh, for fun.

Page 37: Containers, Docker, and Microservices: the Terrific Trio
Page 38: Containers, Docker, and Microservices: the Terrific Trio

any app

Page 39: Containers, Docker, and Microservices: the Terrific Trio

If it runs on Linux, it will run in Docker

Web appsAPI backendsDatabases (SQL, NoSQL)Big dataMessage queuesAnd more

Page 40: Containers, Docker, and Microservices: the Terrific Trio

If it runs on Linux, it will run in Docker

Firefox-in-DockerXorg-in-DockerVPN-in-DockerFirewall-in-DockerDocker-in-DockerKVM-in-Docker

Page 41: Containers, Docker, and Microservices: the Terrific Trio
Page 42: Containers, Docker, and Microservices: the Terrific Trio

anywhere

Page 43: Containers, Docker, and Microservices: the Terrific Trio

anywhere*

*Limitations may apply.

Page 44: Containers, Docker, and Microservices: the Terrific Trio

Docker has official support for:

Intel 64 bits (x86_64) codeRecent kernels (3.8 and above)Coming soon: Windows Containers(If you have questions about this, ask Microsoft!)

Page 45: Containers, Docker, and Microservices: the Terrific Trio

“Rumors” say that people also run on:

Intel 32 bitsARM 32 and 64 bitsMIPSPower8Older kernels (please don't)

Note: the main issue is that the Docker Hub registry is not arch-aware, and images are not compatible.

Page 46: Containers, Docker, and Microservices: the Terrific Trio

CONTAINERSThey're stable, they said. Stack them, they said.

Page 47: Containers, Docker, and Microservices: the Terrific Trio

running stacks of

containers

Page 48: Containers, Docker, and Microservices: the Terrific Trio
Page 49: Containers, Docker, and Microservices: the Terrific Trio

First steps

Online tutorial (in browser, JS based, zero install)http://www.docker.com/tryit/

boot2docker (25 MB universal VM image)http://boot2docker.io/

Scary install scriptcurl -sSL https://get.docker.com/ | sh

We have ordinary packages too!And most clouds have Docker images

Page 50: Containers, Docker, and Microservices: the Terrific Trio

Checklist

Install boot2dockerRun your first container (echo hello world)Write your first DockerfileCreate your Docker Hub account (free)Push image to Docker HubSetup automated buildRun your first complex app with Fig

Page 51: Containers, Docker, and Microservices: the Terrific Trio
Page 52: Containers, Docker, and Microservices: the Terrific Trio

Fig

Run your stack with one command: fig upDescribe your stack with one file: fig.ymlExample: run a (one node) Mesos cluster- Mesos master

- Mesos slave

- Volt framework

Page 53: Containers, Docker, and Microservices: the Terrific Trio

master: image: redjack/mesos-master command: mesos-master --work_dir=/mesos ports: - 5050:5050

slave: image: redjack/mesos-slave links: - master:master command: mesos-slave --master=master:5050 --containerizers=docker,mesos volumes: - /sys/fs/cgroup:/sys/fs/cgroup - /var/run/docker.sock:/var/run/docker.sock - /usr/bin/docker:/bin/docker

volt: image: volt/volt links: - master:master command: --master=master:5050 ports: - 8080:8080

Page 54: Containers, Docker, and Microservices: the Terrific Trio
Page 55: Containers, Docker, and Microservices: the Terrific Trio

?

Page 56: Containers, Docker, and Microservices: the Terrific Trio

what's next?

Page 57: Containers, Docker, and Microservices: the Terrific Trio
Page 58: Containers, Docker, and Microservices: the Terrific Trio

Advanced topics

All Things Dockerhttp://blog.docker.com/

Running your own private registryhttps://github.com/docker/docker-registry

Containers and securityhttp://www.slideshare.net/jpetazzo/docker-linux-containers-lxc-and-securityhttps://medium.com/@ewindisch/on-the-security-of-containers-2c60ffe25a9e

Service discovery(look for “ambassador pattern”)

… And more!

Page 59: Containers, Docker, and Microservices: the Terrific Trio

thank you!questions?

Page 60: Containers, Docker, and Microservices: the Terrific Trio

Would You Like To Know More?

Get in touch on Freenode#docker #docker-dev

Ask me tricky [email protected]

Get your own Docker Hub on [email protected]

Follow us on Twitter@docker, @jpetazzo

Page 61: Containers, Docker, and Microservices: the Terrific Trio