Ruby and Docker on Rails

Muriel Salvan
Muriel SalvanRuby/Rails expert, Founder of X-Aeon Solutions at X-Aeon Solutions
Ruby and
Muriel Salvan
X-Aeon Solutions
Feb 04th 2014
Riviera.rb

on Rails
Who am I?
Muriel Salvan
Freelance Developer
Founder of X-Aeon Solutions
Open Source advocate
Ruby / Rails expert
Co-founder of RivieraRB
@MurielSalvan
Github
SourceForge
My tech blog
Muriel@X-Aeon.com
Let's talk about cargo transport
(that's why you came here, right?)
"I want my piano to be delivered
from Nice to London"
"I also want my barrel of wine
delivered from Nice to London."
"Hey! Don't forget my bags of rice
too!"
How ?
"By train, plane, boat, truck, bus,
mule, or whatever!"
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)
Ruby and Docker on Rails
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
Ruby and Docker on Rails
Static website

Do services and apps
User DB
Queue
interact appropriately?
Web frontend
Background workers

Development VM

Analytics DB
API endpoint

Production Cluster

Public Cloud
QA Can I migrate smoothly and
server
Disaster recovery Contributor’s laptop
quickly?
Customer Data Center
Production Servers
Static website

User DB

Queue

Analytics DB

Background workers

API endpoint

Web frontend
Production Cluster

QA server
Customer Data Center
Development VM

Disaster recovery
Production Servers

Contributor’s laptop
Public Cloud
So what does Docker bring?
1- File systems images
Structured in layers (storing diffs only)
● Layers are reused between images
●

Clever!
2- Processes run in a contained
environment (containers)
It's chroot on steroids!

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
●
3- A public repository of images
Pull and push images
● Build them from Github projects
● Be part of a great community!
●
"Is it a yet-another-virtualizationsolution?"
No.
Processes run by Docker
share the host Kernel
● No device emulation
● No boot sequence
● Architectures and platforms
between Host and containers
must match
●
"So where is the portability?"
●

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...
●
It's blazingly fast!!!
A few ms to load the container and run the
command
Use cases
Get running clusters on a single host
Awesome to test them!
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!
Deployments become sooo easy
Like "push"-and-"pull"-easy!
Lightweight virtualization too
Ruby and Docker on Rails
"How do we create images?"
Docker files
Describe commands to be run to create an image
# Nginx
#
# VERSION

0.0.1

FROM
ubuntu
MAINTAINER Guillaume J. Charmes
<guillaume@dotcloud.com>
# 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
Docker file

docker build .
Image
"And how do we run a process in a
container?"
Image

docker run <image> <cmd>
Container
running <Cmd>
"I want to create a modified image"
Container

docker commit <container> <image name>

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

docker push <image>
Registry
Defaults to
http://index.docker.io
"And now my friend wants to get my
wonderful image to play with!"
Yeah, sure... whatever
Registry
docker search <image name>
docker pull <image>
Image
Ruby and Docker on Rails
"Wasn't that supposed to be a Ruby
meetup?"
Let's simulate a Rails cluster with a
balancing Ruby proxy in front!
3000
Docker container
A

5000

5001

5002

5003

5004

3000

3000

3000

3000

3000

Docker container Docker container Docker container Docker container Docker container
B
B
B
B
B
1. Create a Ruby image:
murielsalvan/ruby
From ubuntu base image
● Using a Dockerfile
● Bonus: Upload it to index.docker.io via Github
●
# Ruby environment
#
# VERSION 0.2
FROM ubuntu
MAINTAINER Muriel Salvan <muriel@x-aeon.com>
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
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
●
3. Launch n docker containers from
murielsalvan/server
●

Map each container port 3000 to host ports 5000+i
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
●
5. Launch 1 docker container from
murielsalvan/proxy
●

Map its guest port 3000 to host port 3000
6. Target localhost:3000
7. Profit!
Ruby and Docker on Rails
Elapsed time (s) on Fibonacci computation

Sponsored by the
WTF effect!

50
45
40
35
30

Launch time
Execution time

25
20
15
10
5
0
Without Docker

With Docker
Memory consumption per container (kB)
180000
160000
140000
120000
Rails
Linux container

100000
80000
60000
40000
20000
0
RSS

VSZ

The Linux container memory is always the same whatever the process in the container:
1,5MB RSS and 32MB VSZ
NOT BAD
Links
Homepage
Index of Docker images
Dockerfile reference
Getting started
That's all, folks!

Source: xkcd

Thanks for attending!
1 of 62

More Related Content

What's hot

Docker BasicsDocker Basics
Docker BasicsDuckDuckGo
1.1K views33 slides
Docker with openstackDocker with openstack
Docker with openstackLiang Bo
896 views18 slides
DockerDocker
DockerMutlu Okuducu
190 views20 slides
Introduction  to DockerIntroduction  to Docker
Introduction to DockerJian Wu
280 views24 slides

What's hot(20)

Docker IntroductionDocker Introduction
Docker Introduction
MANAOUIL Karim329 views
Docker BasicsDocker Basics
Docker Basics
DuckDuckGo1.1K views
Docker with openstackDocker with openstack
Docker with openstack
Liang Bo896 views
DockerDocker
Docker
Mutlu Okuducu190 views
Introduction  to DockerIntroduction  to Docker
Introduction to Docker
Jian Wu280 views
Learning Docker with ThomasLearning Docker with Thomas
Learning Docker with Thomas
Thomas Tong, FRM, PMP424 views
DockerDocker
Docker
Patrick Oberdorf11.2K views
JOSA TechTalk: Introduction to dockerJOSA TechTalk: Introduction to docker
JOSA TechTalk: Introduction to docker
Jordan Open Source Association507 views
Introduction to DockerIntroduction to Docker
Introduction to Docker
Google Developer Group Zürich864 views
Docker introduction for Carbon ITDocker introduction for Carbon IT
Docker introduction for Carbon IT
yannick grenzinger155 views
Intro To DockerIntro To Docker
Intro To Docker
Jessica Lucci460 views
Docker and the Linux KernelDocker and the Linux Kernel
Docker and the Linux Kernel
Docker, Inc.16.7K views
docker installation and basicsdocker installation and basics
docker installation and basics
Walid Ashraf838 views
Docker IntroductionDocker Introduction
Docker Introduction
Jeffrey Ellin631 views
Docker introductionDocker introduction
Docker introduction
dotCloud455.8K views
Docker 101 - Getting startedDocker 101 - Getting started
Docker 101 - Getting started
Matheus Marabesi491 views
Docker - The Linux ContainerDocker - The Linux Container
Docker - The Linux Container
Balaji Rajan13.5K views

Similar to Ruby and Docker on Rails

Docker introDocker intro
Docker introNoelMc Grath
1.8K views27 slides
Docker open stack bostonDocker open stack boston
Docker open stack bostondotCloud
4.7K views27 slides

Similar to Ruby and Docker on Rails(20)

Containing the world with DockerContaining the world with Docker
Containing the world with Docker
Giuseppe Piccolo233 views
Docker & Daily DevOpsDocker & Daily DevOps
Docker & Daily DevOps
Satria Ady Pradana128 views
Docker and-daily-devopsDocker and-daily-devops
Docker and-daily-devops
Satria Ady Pradana1.1K views
Docker introDocker intro
Docker intro
NoelMc Grath1.8K views
Docker and OpenStack Boston MeetupDocker and OpenStack Boston Meetup
Docker and OpenStack Boston Meetup
Kamesh Pemmaraju2.2K views
Docker open stack bostonDocker open stack boston
Docker open stack boston
dotCloud4.7K views
OpenStack BostonOpenStack Boston
OpenStack Boston
Docker, Inc.617 views
Application Deployment on OpenstackApplication Deployment on Openstack
Application Deployment on Openstack
Docker, Inc.4.8K views
DockerDocker
Docker
Brian Hogan1.2K views
Develop with linux containers and dockerDevelop with linux containers and docker
Develop with linux containers and docker
Fabio Fumarola1.4K views
Docker presentationDocker presentation
Docker presentation
Shankar Chaudhary4.8K views
Intro to Docker November 2013Intro to Docker November 2013
Intro to Docker November 2013
Docker, Inc.1.4K views
Docker for developersDocker for developers
Docker for developers
DrupalDay317 views
Docker for developersDocker for developers
Docker for developers
sparkfabrik511 views

Recently uploaded(20)

The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)
CSUC - Consorci de Serveis Universitaris de Catalunya59 views
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh36 views
Liqid: Composable CXL PreviewLiqid: Composable CXL Preview
Liqid: Composable CXL Preview
CXL Forum120 views
ChatGPT and AI for Web DevelopersChatGPT and AI for Web Developers
ChatGPT and AI for Web Developers
Maximiliano Firtman161 views
Java Platform Approach 1.0 - Picnic MeetupJava Platform Approach 1.0 - Picnic Meetup
Java Platform Approach 1.0 - Picnic Meetup
Rick Ossendrijver24 views

Ruby and Docker on Rails

  • 1. Ruby and Muriel Salvan X-Aeon Solutions Feb 04th 2014 Riviera.rb on Rails
  • 3. Muriel Salvan Freelance Developer Founder of X-Aeon Solutions Open Source advocate Ruby / Rails expert Co-founder of RivieraRB
  • 5. Let's talk about cargo transport (that's why you came here, right?)
  • 6. "I want my piano to be delivered from Nice to London"
  • 7. "I also want my barrel of wine delivered from Nice to London."
  • 8. "Hey! Don't forget my bags of rice too!"
  • 10. "By train, plane, boat, truck, bus, mule, or whatever!"
  • 11. 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)
  • 13. 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
  • 15. Static website Do services and apps User DB Queue interact appropriately? Web frontend Background workers Development VM Analytics DB API endpoint Production Cluster Public Cloud QA Can I migrate smoothly and server Disaster recovery Contributor’s laptop quickly? Customer Data Center Production Servers
  • 16. Static website User DB Queue Analytics DB Background workers API endpoint Web frontend Production Cluster QA server Customer Data Center Development VM Disaster recovery Production Servers Contributor’s laptop Public Cloud
  • 17. So what does Docker bring?
  • 18. 1- File systems images Structured in layers (storing diffs only) ● Layers are reused between images ● Clever!
  • 19. 2- Processes run in a contained environment (containers) It's chroot on steroids! 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 ●
  • 20. 3- A public repository of images Pull and push images ● Build them from Github projects ● Be part of a great community! ●
  • 21. "Is it a yet-another-virtualizationsolution?"
  • 22. No.
  • 23. Processes run by Docker share the host Kernel ● No device emulation ● No boot sequence ● Architectures and platforms between Host and containers must match ●
  • 24. "So where is the portability?"
  • 25. ● 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... ●
  • 26. It's blazingly fast!!! A few ms to load the container and run the command
  • 28. Get running clusters on a single host Awesome to test them!
  • 29. 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!
  • 30. Deployments become sooo easy Like "push"-and-"pull"-easy!
  • 33. "How do we create images?"
  • 34. Docker files Describe commands to be run to create an image
  • 35. # Nginx # # VERSION 0.0.1 FROM ubuntu MAINTAINER Guillaume J. Charmes <guillaume@dotcloud.com> # 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
  • 37. "And how do we run a process in a container?"
  • 38. Image docker run <image> <cmd> Container running <Cmd>
  • 39. "I want to create a modified image"
  • 41. "Hey! I want to deploy my image for the world to see!"
  • 42. Image docker push <image> Registry Defaults to http://index.docker.io
  • 43. "And now my friend wants to get my wonderful image to play with!" Yeah, sure... whatever
  • 44. Registry docker search <image name> docker pull <image> Image
  • 46. "Wasn't that supposed to be a Ruby meetup?"
  • 47. Let's simulate a Rails cluster with a balancing Ruby proxy in front!
  • 48. 3000 Docker container A 5000 5001 5002 5003 5004 3000 3000 3000 3000 3000 Docker container Docker container Docker container Docker container Docker container B B B B B
  • 49. 1. Create a Ruby image: murielsalvan/ruby From ubuntu base image ● Using a Dockerfile ● Bonus: Upload it to index.docker.io via Github ●
  • 50. # Ruby environment # # VERSION 0.2 FROM ubuntu MAINTAINER Muriel Salvan <muriel@x-aeon.com> 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
  • 51. 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 ●
  • 52. 3. Launch n docker containers from murielsalvan/server ● Map each container port 3000 to host ports 5000+i
  • 53. 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 ●
  • 54. 5. Launch 1 docker container from murielsalvan/proxy ● Map its guest port 3000 to host port 3000
  • 58. Elapsed time (s) on Fibonacci computation Sponsored by the WTF effect! 50 45 40 35 30 Launch time Execution time 25 20 15 10 5 0 Without Docker With Docker
  • 59. Memory consumption per container (kB) 180000 160000 140000 120000 Rails Linux container 100000 80000 60000 40000 20000 0 RSS VSZ The Linux container memory is always the same whatever the process in the container: 1,5MB RSS and 32MB VSZ
  • 61. Links Homepage Index of Docker images Dockerfile reference Getting started
  • 62. That's all, folks! Source: xkcd Thanks for attending!