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
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
200
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
310
私なりのAIのご紹介 [2024年版]
qt_luigi
1
120
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
17
13k
複雑性の高いオブジェクト編集に向き合う: プラガブルなReactフォーム設計
righttouch
PRO
0
120
なぜCodeceptJSを選んだか
goataka
0
160
権威ドキュメントで振り返る2024 #年忘れセキュリティ2024
hirotomotaguchi
2
750
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
OpenAIの蒸留機能(Model Distillation)を使用して運用中のLLMのコストを削減する取り組み
pharma_x_tech
4
560
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
220
kargoの魅力について伝える
magisystem0408
0
210
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Designing for Performance
lara
604
68k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
Why Our Code Smells
bkeepers
PRO
335
57k
Code Reviewing Like a Champion
maltzj
520
39k
Visualization
eitanlees
146
15k
Done Done
chrislema
181
16k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
For a Future-Friendly Web
brad_frost
175
9.4k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Become a Pro
speakerdeck
PRO
26
5k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
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