ruby and docker on rails
Post on 16-Apr-2017
5.658 Views
Preview:
TRANSCRIPT
Ruby and on Rails
Muriel SalvanX-Aeon SolutionsFeb 04th 2014Riviera.rb
Who am I?
Muriel SalvanFreelance DeveloperFounder of X-Aeon SolutionsOpen Source advocateRuby / Rails expertCo-founder of RivieraRB
@MurielSalvanGithubSourceForgeMy tech blogMuriel@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)
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
Static websiteWeb frontend User DBQueueAnalytics DBBackground workersAPI endpointDevelopment VMQA serverPublic CloudDisaster recoveryContributors laptopProduction ServersProduction Cluster
Customer Data Center
Do services and apps interact appropriately?Can I migrate smoothly and quickly?
Static websiteWeb frontend User DBQueueAnalytics DBBackground workersAPI endpointDevelopment VMQA serverPublic CloudDisaster recoveryContributors laptopProduction ServersProduction Cluster
Customer Data Center
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)
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!
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-virtualization-solution?"
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
"How do we create images?"
Docker files
Describe commands to be run to create an image
# Nginx## VERSION 0.0.1
FROM ubuntuMAINTAINER Guillaume J. Charmes
# make sure the package repository is up to dateRUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.listRUN apt-get update
RUN apt-get install -y inotify-tools nginx apache2 openssh-server
docker build .
Docker fileImage
"And how do we run a process in a container?"
docker run
ImageContainerrunning
"I want to create a modified image"
docker commit
ImageContainer
"Hey! I want to deploy my image for the world to see!"
docker push
ImageRegistryDefaults tohttp://index.docker.io
"And now my friend wants to get my wonderful image to play with!"
Yeah, sure... whatever
docker search docker pull
ImageRegistry
"Wasn't that supposed to be a Ruby meetup?"
Let's simulate a Rails cluster with a balancing Ruby proxy in front!
Docker containerB
Docker containerB
Docker containerB
Docker containerB
Docker containerB
Docker containerA3000
3000
3000
3000
3000
5000
5001
5002
5003
5004
3000
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 ubuntuMAINTAINER Muriel Salvan
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.listRUN apt-get updateRUN 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!
Sponsored by theWTF effect!
The Linux container memory is always the same whatever the process in the container:1,5MB RSS and 32MB VSZ
NOT BAD
Links
HomepageIndex of Docker imagesDockerfile referenceGetting started
This presentation is available under CC-BY license by Muriel Salvan
Source: xkcd
That's all, folks!
Thanks for attending!
Elapsed time (s) on Fibonacci computationWithout DockerWith Docker
Execution time45.792896932666738.0897856636667
Launch time0.1644531706666612.712914481
Memory consumption per container (kB)RSSVSZ
Rails60000155268
Linux container150432284
Click to edit the title text format
top related