Slide 1

Slide 1 text

Ruby and on Rails Muriel Salvan X-Aeon Solutions Feb 04th 2014 Riviera.rb

Slide 2

Slide 2 text

Who am I?

Slide 3

Slide 3 text

Muriel Salvan Freelance Developer Founder of X-Aeon Solutions Open Source advocate Ruby / Rails expert Co-founder of RivieraRB

Slide 4

Slide 4 text

@MurielSalvan Github SourceForge My tech blog [email protected]

Slide 5

Slide 5 text

Let's talk about cargo transport (that's why you came here, right?)

Slide 6

Slide 6 text

"I want my piano to be delivered from Nice to London"

Slide 7

Slide 7 text

"I also want my barrel of wine delivered from Nice to London."

Slide 8

Slide 8 text

"Hey! Don't forget my bags of rice too!"

Slide 9

Slide 9 text

How ?

Slide 10

Slide 10 text

"By train, plane, boat, truck, bus, mule, or whatever!"

Slide 11

Slide 11 text

Do I worry about how goods interact (e.g. coffee beans next to spices) Can I transport quickly and smoothly (e.g. from boat to train to truck)

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

A standard container that is loaded with virtually any goods, and stays sealed until it reaches final delivery. …in between, can be loaded and unloaded, stacked, transported efficiently over long distances, and transferred from one mode of transport to another

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Static website Web frontend User DB Queue Analytics DB Background workers API endpoint Development VM QA server Public Cloud Disaster recovery Contributor’s laptop Production Servers Production Cluster Customer Data Center Do services and apps interact appropriately? Can I migrate smoothly and quickly?

Slide 16

Slide 16 text

Static website Web frontend User DB Queue Analytics DB Background workers API endpoint Development VM QA server Public Cloud Disaster recovery Contributor’s laptop Production Servers Production Cluster Customer Data Center

Slide 17

Slide 17 text

So what does Docker bring?

Slide 18

Slide 18 text

1- File systems images ● Structured in layers (storing diffs only) ● Layers are reused between images Clever!

Slide 19

Slide 19 text

2- Processes run in a contained environment (containers) ● Using images' file systems (isolated like in chroot) ● In a separate process space (using Linux containers) ● With a specific network interface ● Can run as root It's chroot on steroids!

Slide 20

Slide 20 text

3- A public repository of images ● Pull and push images ● Build them from Github projects ● Be part of a great community!

Slide 21

Slide 21 text

"Is it a yet-another-virtualization- solution?"

Slide 22

Slide 22 text

No.

Slide 23

Slide 23 text

● Processes run by Docker share the host Kernel ● No device emulation ● No boot sequence ● Architectures and platforms between Host and containers must match

Slide 24

Slide 24 text

"So where is the portability?"

Slide 25

Slide 25 text

● Containers can be run on any Kernel (>= 3.8, Linux 64b only for now) ● Whatever the Linux distro ● If it runs on the Host, it can run from a container ● Physical, virtual, cloud...

Slide 26

Slide 26 text

It's blazingly fast!!! A few ms to load the container and run the command

Slide 27

Slide 27 text

Use cases

Slide 28

Slide 28 text

Get running clusters on a single host Awesome to test them!

Slide 29

Slide 29 text

Ensure the environment your process runs in is the same in dev, test and prod Bring your environment along with your process. Sandboxes everywhere! You'll love that!

Slide 30

Slide 30 text

Deployments become sooo easy Like "push"-and-"pull"-easy!

Slide 31

Slide 31 text

Lightweight virtualization too

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

"How do we create images?"

Slide 34

Slide 34 text

Docker files Describe commands to be run to create an image

Slide 35

Slide 35 text

# Nginx # # VERSION 0.0.1 FROM ubuntu MAINTAINER Guillaume J. Charmes # make sure the package repository is up to date RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list RUN apt-get update RUN apt-get install -y inotify-tools nginx apache2 openssh-server

Slide 36

Slide 36 text

docker build . Docker file Image

Slide 37

Slide 37 text

"And how do we run a process in a container?"

Slide 38

Slide 38 text

docker run Image Container running

Slide 39

Slide 39 text

"I want to create a modified image"

Slide 40

Slide 40 text

docker commit Image Container

Slide 41

Slide 41 text

"Hey! I want to deploy my image for the world to see!"

Slide 42

Slide 42 text

docker push Image Registry Defaults to http://index.docker.io

Slide 43

Slide 43 text

"And now my friend wants to get my wonderful image to play with!" Yeah, sure... whatever

Slide 44

Slide 44 text

docker search docker pull Image Registry

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

"Wasn't that supposed to be a Ruby meetup?"

Slide 47

Slide 47 text

Let's simulate a Rails cluster with a balancing Ruby proxy in front!

Slide 48

Slide 48 text

Docker container B Docker container B Docker container B Docker container B Docker container B Docker container A 3000 3000 3000 3000 3000 5000 5001 5002 5003 5004 3000

Slide 49

Slide 49 text

1. Create a Ruby image: murielsalvan/ruby ● From ubuntu base image ● Using a Dockerfile ● Bonus: Upload it to index.docker.io via Github

Slide 50

Slide 50 text

# Ruby environment # # VERSION 0.2 FROM ubuntu MAINTAINER Muriel Salvan RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list RUN apt-get update RUN apt-get upgrade -y RUN apt-get install -y build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev ADD http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.0.tar.gz /tmp/ RUN cd /tmp && \ tar -xzf ruby-2.1.0.tar.gz && \ cd ruby-2.1.0 && \ ./configure && \ make && \ make install && \ cd .. && \ rm -rf ruby-2.1.0 && \ rm -f ruby-2.1.0.tar.gz

Slide 51

Slide 51 text

2. Create a Rails server image: murielsalvan/server ● From murielsalvan/ruby base image ● Using an interactive bash in a container to install and configure the Rails application ● Add a startup command: rails s ● Open default port 3000

Slide 52

Slide 52 text

3. Launch n docker containers from murielsalvan/server ● Map each container port 3000 to host ports 5000+i

Slide 53

Slide 53 text

4. Create a new image for the Ruby proxy: murielsalvan/proxy ● Based on murielsalvan/ruby ● Using an interactive bash to install and use em-proxy, targetting servers on ports 5000+i ● Add a startup command: ruby -w balancing.rb ● Open port 3000

Slide 54

Slide 54 text

5. Launch 1 docker container from murielsalvan/proxy ● Map its guest port 3000 to host port 3000

Slide 55

Slide 55 text

6. Target localhost:3000

Slide 56

Slide 56 text

7. Profit!

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Without Docker With Docker 0 5 10 15 20 25 30 35 40 45 50 Elapsed time (s) on Fibonacci computation Launch time Execution time Sponsored by the WTF effect!

Slide 59

Slide 59 text

RSS VSZ 0 20000 40000 60000 80000 100000 120000 140000 160000 180000 Memory consumption per container (kB) Rails Linux container The Linux container memory is always the same whatever the process in the container: 1,5MB RSS and 32MB VSZ

Slide 60

Slide 60 text

NOT BAD

Slide 61

Slide 61 text

Links Homepage Index of Docker images Dockerfile reference Getting started

Slide 62

Slide 62 text

Source: xkcd That's all, folks! Thanks for attending!