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
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
6. Docker manages containers
• Builds images to run as containers
• Can manage entire applications with docker-compose
• Provision machines with docker-machine
6
7. A container is a virtualization layer
— sort of like a VM — but with
some fundamental differences
8. 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
20. • ~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
21. 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)
22. • 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
23. 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
24. Use the Docker Hub to find and
store images to use in your project.
Use Docker Compose to build it.
27. 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
29. 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
30. 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
33. How can I get containerized services to
communicate with one another?container linking, environment variables…
and of course, a little config sugar
38. 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