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.
Building  Rails  
Applications  with  
Docker
Laura Frank @rhein_wein
Software Engineer @codeship
Today’s  Agenda
• An introduction to containers: what are they, and what
makes them different from virtual machines?
• The...
An  Introduction  to  
Containerization
Docker  !=  containers
Docker  manages  containers
• Builds images to run as containers
• Can manage entire applications with docker-compose
• Pr...
A container is a virtualization layer
— sort of like a VM — but with
some fundamental differences
Containers
• Run in a self-contained execution environment
• Share the kernel of host system
• Are isolated from other con...
infrastructure
host OS
hypervisor
$
guest OS
libraries
service 0
$ guest OS $ guest OS
libraries
service 2
libraries
servi...
libraries librarieslibraries
infrastructure
host OS
service 0 service 2service 1
host OS
libraries librarieslibraries
infrastructure
container runtime engine
service 0 service 2service 1
Getting started with containers may
initially seem more complex…
…But they greatly reduce the
amount of time and space needed
to run your application
Spend less time provisioning,
rebooting, and fighting with
dependencies, and more time building
what you want.
TL;DR
The  Docker  Ecosystem  
Build Ship Run
Docker  Images
Are images containers?
No… an image is like a class, and a container is an
instance of that class
The  Docker  Hub
19
• ~15,000 images that you can pull down and use in your
own projects
• Also includes additional features like webhooks, bu...
Different  Types  of  Images
• Service: self-contained images that provide a self-
contained service out-of-the-box. Postg...
• Build them yourself by creating a Dockerfile
• docker	
  build	
  -­‐t	
  image_name	
  .	
  	
  

#	
  don’t	
  forget	...
A  Rails  Dockerfile
FROM rails:4.2.4
MAINTAINER Laura Frank <laura@codeship.com>
RUN mkdir -p /var/app
COPY . /var/app
WO...
Use the Docker Hub to find and
store images to use in your project.
Use Docker Compose to build it.
Docker  Compose
25
Building  Your  First  Rails  
App  with  Docker
Installing  Docker
• The old way: boot2docker
• The new way: Docker Toolbox
• Docker Client, Machine, Engine, Compose (on ...
Installing  Docker
🐳  docker.com/toolbox
Development  Goals
Run a Rails app in a container, so that a developer can:
• view the app running in the browser
• edit f...
Remember  This?
FROM rails:4.2.4
MAINTAINER Laura Frank <laura@codeship.com>
RUN mkdir -p /var/app
COPY Gemfile /var/app/G...
🚉 🐘
A  Multi-­‐Container  Rails  App
Rails  App Postgres
❤
How can I get containerized services to
communicate with one another?container linking, environment variables…
and of cour...
Docker Compose makes this easy.
db:	
  
	
  	
  image:	
  postgres	
  
web:	
  
	
  	
  build:	
  .	
  
	
  	
  command:	
  bundle	
  exec	
  rails	
  s	
...
development:	
  &default	
  
	
  	
  adapter:	
  postgresql	
  
	
  	
  encoding:	
  unicode	
  
	
  	
  database:	
  post...
Ship  It
A simple CI/CD workflow would include
• running tests
• building a new Docker image
• pushing that image to a reg...
#alwayskeepshipping
thanks!
Rails Applications with Docker
Rails Applications with Docker
Rails Applications with Docker
Upcoming SlideShare
Loading in …5
×

Rails Applications with Docker

7,684 views

Published on

A brief introduction to containerization, Docker, and getting started with your first containerized Rails application. Source code can be found at https://github.com/rheinwein/rails-demo-apps

Published in: Technology
  • Sex in your area is here: ❶❶❶ http://bit.ly/2ZDZFYj ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating direct: ❶❶❶ http://bit.ly/2ZDZFYj ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Rails Applications with Docker

  1. 1. Building  Rails   Applications  with   Docker Laura Frank @rhein_wein Software Engineer @codeship
  2. 2. Today’s  Agenda • An introduction to containers: what are they, and what makes them different from virtual machines? • The Docker ecosystem • Working with Docker on a Rails project 2
  3. 3. An  Introduction  to   Containerization
  4. 4. Docker  !=  containers
  5. 5. Docker  manages  containers • Builds images to run as containers • Can manage entire applications with docker-compose • Provision machines with docker-machine 6
  6. 6. A container is a virtualization layer — sort of like a VM — but with some fundamental differences
  7. 7. Containers • Run in a self-contained execution environment • Share the kernel of host system • Are isolated from other containers • Have fast boot times & low overhead 8
  8. 8. infrastructure host OS hypervisor $ guest OS libraries service 0 $ guest OS $ guest OS libraries service 2 libraries service 1
  9. 9. libraries librarieslibraries infrastructure host OS service 0 service 2service 1
  10. 10. host OS libraries librarieslibraries infrastructure container runtime engine service 0 service 2service 1
  11. 11. Getting started with containers may initially seem more complex…
  12. 12. …But they greatly reduce the amount of time and space needed to run your application
  13. 13. Spend less time provisioning, rebooting, and fighting with dependencies, and more time building what you want. TL;DR
  14. 14. The  Docker  Ecosystem  
  15. 15. Build Ship Run
  16. 16. Docker  Images
  17. 17. Are images containers? No… an image is like a class, and a container is an instance of that class
  18. 18. The  Docker  Hub 19
  19. 19. • ~15,000 images that you can pull down and use in your own projects • Also includes additional features like webhooks, build triggers, authentication, and private repositories • Use either the web GUI or the CLI — familiar workflow of login, push, pull, search, etc. The  Docker  Hub
  20. 20. Different  Types  of  Images • Service: self-contained images that provide a self- contained service out-of-the-box. Postgres, MySQL. • Project Base: intended to serve as a base for your own project; do not directly provide a service. Ruby, golang. • Official Images: maintained by the organization/ company themselves (i.e. the official Rails image)
  21. 21. • Build them yourself by creating a Dockerfile • docker  build  -­‐t  image_name  .    
 #  don’t  forget  the  dot!   • run docker  images  to see all of the images you’ve downloaded or built Your  Own  Docker  Images
  22. 22. A  Rails  Dockerfile FROM rails:4.2.4 MAINTAINER Laura Frank <laura@codeship.com> RUN mkdir -p /var/app COPY . /var/app WORKDIR /var/app RUN bundle install CMD rails s -b 0.0.0.0 set versions here
  23. 23. Use the Docker Hub to find and store images to use in your project. Use Docker Compose to build it.
  24. 24. Docker  Compose 25
  25. 25. Building  Your  First  Rails   App  with  Docker
  26. 26. Installing  Docker • The old way: boot2docker • The new way: Docker Toolbox • Docker Client, Machine, Engine, Compose (on a Mac), Kitematic, and Virtual Box • You can migrate your boot2docker VM to a Docker Machine machine — check the docs
  27. 27. Installing  Docker 🐳  docker.com/toolbox
  28. 28. Development  Goals Run a Rails app in a container, so that a developer can: • view the app running in the browser • edit files in a local environment and see the changes • run rake tasks like migrations • see log output
  29. 29. Remember  This? FROM rails:4.2.4 MAINTAINER Laura Frank <laura@codeship.com> RUN mkdir -p /var/app COPY Gemfile /var/app/Gemfile WORKDIR /var/app RUN bundle install CMD rails s -b 0.0.0.0
  30. 30. 🚉 🐘 A  Multi-­‐Container  Rails  App Rails  App Postgres ❤
  31. 31. How can I get containerized services to communicate with one another?container linking, environment variables… and of course, a little config sugar
  32. 32. Docker Compose makes this easy.
  33. 33. db:      image:  postgres   web:      build:  .      command:  bundle  exec  rails  s  -­‐p  3000  -­‐b  '0.0.0.0'      volumes:          -­‐  .:/var/app      ports:          -­‐  '3333:3000'      links:          -­‐  db docker-­‐compose.yml
  34. 34. development:  &default      adapter:  postgresql      encoding:  unicode      database:  postgres      pool:  5      username:  postgres      password:      host:  db config/database.yml
  35. 35. Ship  It A simple CI/CD workflow would include • running tests • building a new Docker image • pushing that image to a registry • firing up containers with the new image
  36. 36. #alwayskeepshipping
  37. 37. thanks!

×