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
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
110
Qiita埋め込み用スライド
naoki_0531
0
5.1k
.NET 9 のパフォーマンス改善
nenonaninu
0
1k
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
350
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
210
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
540
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
160
20241220_S3 tablesの使い方を検証してみた
handy
4
620
ガバメントクラウドのセキュリティ対策事例について
fujisawaryohei
0
560
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
170
Fanstaの1年を大解剖! 一人SREはどこまでできるのか!?
syossan27
2
170
サービスでLLMを採用したばっかりに振り回され続けたこの一年のあれやこれや
segavvy
2
490
Featured
See All Featured
Designing for Performance
lara
604
68k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Gamification - CAS2011
davidbonilla
80
5.1k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Typedesign – Prime Four
hannesfritz
40
2.4k
The Language of Interfaces
destraynor
154
24k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Building Applications with DynamoDB
mza
91
6.1k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
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