Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Containerized Applications with Docker
Search
Laura Frank
March 26, 2015
Technology
2
150
Containerized Applications with Docker
An introduction to developing applications with Docker. Given at Ancient City Ruby 2015
Laura Frank
March 26, 2015
Tweet
Share
More Decks by Laura Frank
See All by Laura Frank
GOTO Night Chicago -- Containerizing your Dev Environment
rheinwein
1
110
Building Containerized Applications with Docker
rheinwein
0
91
Other Decks in Technology
See All in Technology
メールヘッダーを見てみよう
hinono
0
110
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
6
54k
Docker Desktop で Docker を始めよう
zembutsu
PRO
0
180
生成AI × 旅行 LLMを活用した旅行プラン生成・チャットボット
kominet_ava
0
160
RubyでKubernetesプログラミング
sat
PRO
4
160
iPadOS18でフローティングタブバーを解除してみた
sansantech
PRO
1
150
Godot Engineについて調べてみた
unsoluble_sugar
0
410
.NET AspireでAzure Functionsやクラウドリソースを統合する
tsubakimoto_s
0
190
2025年に挑戦したいこと
molmolken
0
160
デジタルアイデンティティ技術 認可・ID連携・認証 応用 / 20250114-OIDF-J-EduWG-TechSWG
oidfj
2
690
あなたの知らないクラフトビールの世界
miura55
0
130
コロプラのオンボーディングを採用から語りたい
colopl
5
1.3k
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
A better future with KSS
kneath
238
17k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.6k
How STYLIGHT went responsive
nonsquared
96
5.3k
Why Our Code Smells
bkeepers
PRO
335
57k
Designing for humans not robots
tammielis
250
25k
Building an army of robots
kneath
302
45k
Documentation Writing (for coders)
carmenintech
67
4.5k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
960
Transcript
Containerized Ruby Applications with Docker Laura Frank rheinwein @rhein_wein
None
+
Containerization: What even is it? How do I use Docker
within my applications? How can I use Docker with Ruby? Three Questions
None
Docker may seem trendy right now… but there’s a reason
it’s popular.
Docker != containers
A tool for managing containers • Executing and running code
• Managing code Docker
First, let’s talk about 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 Containers
LXC/libcontainer/… - container format namespaces - isolation cgroups - sharing
unionfs - layering Containers
A container is a virtualization layer — sort of like
a VM — but with some fundamental differences Containers can work in conjunction with or in place of virtual machines (VMs).
hardware host OS hypervisor $ guest OS libraries web $
guest OS $ guest OS libraries DB libraries web
hardware host OS libraries web libraries DB libraries web
hardware host OS container runtime engine libraries libraries web web
DB
Containers have slightly more complexity but They reduce the amount
of time/space resources needed to run your application
None
A tool for managing containers • Executing and running code
• Managing code Docker
Engine Hub docker.com
The Docker Hub • Ideas • News • Images (Docker
Registry)
registry.hub.docker.com
Using Ruby with Docker
Installing Docker
Anything else? You need to use a lightweight VM. Pro
Tip: Boot2Docker (OSX and Windows) Installing Docker Linux? Install Docker with official packages. Kitematic (OSX)
CLI REST API docs.docker.com Interacting with Docker
None
Docker Images An image is controlled by a Dockerfile docker
build -t foo/bar . docker pull foo/bar
• Static: all files and code are contained in image
• Dynamic: link folders to actively modify code (development only) Sehr wichtig/very important/¡muy importante! Docker Images
FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <
[email protected]
> EXPOSE 4567 RUN mkdir
-p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile
FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <
[email protected]
> EXPOSE 4567 RUN mkdir
-p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile
FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <
[email protected]
> EXPOSE 4567 RUN mkdir
-p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile
FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <
[email protected]
> EXPOSE 4567 RUN mkdir
-p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile
FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <
[email protected]
> EXPOSE 4567 RUN mkdir
-p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile
FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <
[email protected]
> EXPOSE 4567 RUN mkdir
-p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile
FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <
[email protected]
> EXPOSE 4567 RUN mkdir
-p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD “ruby hello_world.rb" Dockerfile
ENV KEY value Declare any environment variables that will be
passed to any RUN command. VOLUME /var/foo VOLUME [“/var/foo”, “/var/bar”] creates a mount point for volumes from host or other containers
FROM centurylink/ruby-base:2.1.2 Dockerfile No need for gemset or version management,
just use a different base image. Base images are great!
Official Ruby Images https://registry.hub.docker.com/_/ruby/ Support for 1.9.3+ docker pull ruby:2.1.X
Repository includes instructions for bootstrapping
Gems From Swipely: docker-api: for interacting with the Docker API
from your Ruby application Over 30 other gems
(Sorry.) …is kind of a pain. Debugging in a Container…
Debugging in a Container Use Pry. require ‘pry’ class Thing
def some_method binding.pry #some brilliant broken code end end
Debugging in a Container No need for a remote session*
Alternatively, use pry command: docker run centurylink/panamax-api pry
None
Application Architecture with Docker
Simply put, Docker architecture is service-oriented architecture. If a service
fails, new containers can be spun up in milliseconds.
DB Web One Service, One Container
Bind 8080:4567 Expose 3306 link One Service, One Container DB
Web
Configuration can happen in two places: The Dockerfile, by baking
config options into the service’s base image The docker run string, by specifying configuration options with various flags Configuring an Application
Bind 8080:4567 Expose 3306 One Service, One Container link DB
Web
Bind 8080:4567 The Dockerfile Link: DB Web FROM centurylink/ruby-base:2.1.2 MAINTAINER
Laura Frank <
[email protected]
> RUN mkdir -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD ["ruby", "hello_world.rb"]
Bind 8080:4567 FROM centurylink/ruby-base:2.1.2 MAINTAINER Laura Frank <
[email protected]
> ENV APIKEY=superSeCrEt01234567abcdef!
RUN mkdir -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app RUN bundle install CMD ["ruby", "hello_world.rb"] The Dockerfile Link: DB Web
Bind 8080:4567 Link: DB The Docker Run String Web docker
run -p 8080:4567 -e “APIKEY=superSeCrEt01234567abcdef!” —-link db:db my-image
The Docker Run String Each container has own docker run
string Can only start one container at a time via CLI Multiple containers can run from the same image Find balance between docker run and Dockerfile
…that sounds like a lot of tedious work.
None
Application Templating Use your own images, or images from the
Docker Registry Specify config options beforehand Run applications with one or two simple commands
Standards tightly coupled with Docker docs.docker.com/compose Dump requirements into docker-compose.yml
and run with docker-compose up Docker Compose
Docker workflow tool Itself a containerized application panamax.io Uses CoreOS,
Fleet, and etcd for orchestration and service discovery
Templating language similar to docker compose Supports remote deployments panamax.io/get-panamax
--- name: Rails with PostgreSQL description: Rails with PostgreSQL images:
- category: Web Tier name: Rails source: rheinwein/rails:latest description: Rails App type: Default expose: [] ports: - host_port: '8080' container_port: '3000' links: - service: Database alias: DB_1 environment: [] volumes: []
Parting Thoughts Extract commonalities from images in order to share
them Don’t include any user- or org-specific configurations in an image or application template Boot2Docker Use an application template
Additional Resources Docker Hub: registry.hub.docker.com Documentation: docs.docker.com Boot2Docker: boot2docker.io Panamax:
panamax.io CenturyLink Labs: centurylinklabs.com
Thanks! Laura Frank rheinwein @rhein_wein