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
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
390
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
950
AIチャットボット開発への生成AI活用
ryomrt
0
170
プロダクト活用度で見えた真実 ホリゾンタルSaaSでの顧客解像度の高め方
tadaken3
0
180
AGIについてChatGPTに聞いてみた
blueb
0
130
Lambdaと地方とコミュニティ
miu_crescent
2
370
Introduction to Works of ML Engineer in LY Corporation
lycorp_recruit_jp
0
140
アプリエンジニアのためのGraphQL入門.pdf
spycwolf
0
100
『Firebase Dynamic Links終了に備える』 FlutterアプリでのAdjust導入とDeeplink最適化
techiro
0
130
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.4k
SSMRunbook作成の勘所_20241120
koichiotomo
3
160
Platform Engineering for Software Developers and Architects
syntasso
1
520
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
A better future with KSS
kneath
238
17k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
For a Future-Friendly Web
brad_frost
175
9.4k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
What's in a price? How to price your products and services
michaelherold
243
12k
The Cult of Friendly URLs
andyhume
78
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