Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ruby and Docker on Rails


Published on

Quick overview of Docker and its usage.
Illustrated with a cluster of Rails applications and a Ruby load balancing proxy on top of them.
This presentation was made during the rivierarb meetup in Sophia-Antipolis on 2014 Feb 04th by Muriel Salvan.

Published in: Technology
  • Be the first to comment

Ruby and Docker on Rails

  1. 1. Ruby and Muriel Salvan X-Aeon Solutions Feb 04th 2014 Riviera.rb on Rails
  2. 2. Who am I?
  3. 3. Muriel Salvan Freelance Developer Founder of X-Aeon Solutions Open Source advocate Ruby / Rails expert Co-founder of RivieraRB
  4. 4. @MurielSalvan Github SourceForge My tech blog
  5. 5. Let's talk about cargo transport (that's why you came here, right?)
  6. 6. "I want my piano to be delivered from Nice to London"
  7. 7. "I also want my barrel of wine delivered from Nice to London."
  8. 8. "Hey! Don't forget my bags of rice too!"
  9. 9. How ?
  10. 10. "By train, plane, boat, truck, bus, mule, or whatever!"
  11. 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)
  12. 12. 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
  13. 13. 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
  14. 14. 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
  15. 15. So what does Docker bring?
  16. 16. 1- File systems images Structured in layers (storing diffs only) ● Layers are reused between images ● Clever!
  17. 17. 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 ●
  18. 18. 3- A public repository of images Pull and push images ● Build them from Github projects ● Be part of a great community! ●
  19. 19. "Is it a yet-another-virtualizationsolution?"
  20. 20. No.
  21. 21. Processes run by Docker share the host Kernel ● No device emulation ● No boot sequence ● Architectures and platforms between Host and containers must match ●
  22. 22. "So where is the portability?"
  23. 23. ● 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... ●
  24. 24. It's blazingly fast!!! A few ms to load the container and run the command
  25. 25. Use cases
  26. 26. Get running clusters on a single host Awesome to test them!
  27. 27. 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!
  28. 28. Deployments become sooo easy Like "push"-and-"pull"-easy!
  29. 29. Lightweight virtualization too
  30. 30. "How do we create images?"
  31. 31. Docker files Describe commands to be run to create an image
  32. 32. # Nginx # # VERSION 0.0.1 FROM ubuntu MAINTAINER Guillaume J. Charmes <> # make sure the package repository is up to date RUN echo "deb precise main universe" > /etc/apt/sources.list RUN apt-get update RUN apt-get install -y inotify-tools nginx apache2 openssh-server
  33. 33. Docker file docker build . Image
  34. 34. "And how do we run a process in a container?"
  35. 35. Image docker run <image> <cmd> Container running <Cmd>
  36. 36. "I want to create a modified image"
  37. 37. Container docker commit <container> <image name> Image
  38. 38. "Hey! I want to deploy my image for the world to see!"
  39. 39. Image docker push <image> Registry Defaults to
  40. 40. "And now my friend wants to get my wonderful image to play with!" Yeah, sure... whatever
  41. 41. Registry docker search <image name> docker pull <image> Image
  42. 42. "Wasn't that supposed to be a Ruby meetup?"
  43. 43. Let's simulate a Rails cluster with a balancing Ruby proxy in front!
  44. 44. 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
  45. 45. 1. Create a Ruby image: murielsalvan/ruby From ubuntu base image ● Using a Dockerfile ● Bonus: Upload it to via Github ●
  46. 46. # Ruby environment # # VERSION 0.2 FROM ubuntu MAINTAINER Muriel Salvan <> RUN echo "deb 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 /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
  47. 47. 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 ●
  48. 48. 3. Launch n docker containers from murielsalvan/server ● Map each container port 3000 to host ports 5000+i
  49. 49. 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 ●
  50. 50. 5. Launch 1 docker container from murielsalvan/proxy ● Map its guest port 3000 to host port 3000
  51. 51. 6. Target localhost:3000
  52. 52. 7. Profit!
  53. 53. 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
  54. 54. 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
  55. 55. NOT BAD
  56. 56. Links Homepage Index of Docker images Dockerfile reference Getting started
  57. 57. That's all, folks! Source: xkcd Thanks for attending!