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
DMARC 対応の話 - MIXI CTO オフィスアワー #04
bbqallstars
1
160
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
AWS Lambdaと歩んだ“サーバーレス”と今後 #lambda_10years
yoshidashingo
1
170
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
750
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
380
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
0
110
AGIについてChatGPTに聞いてみた
blueb
0
130
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
190
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
580
強いチームと開発生産性
onk
PRO
34
11k
Featured
See All Featured
Fireside Chat
paigeccino
34
3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
A Philosophy of Restraint
colly
203
16k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Git: the NoSQL Database
bkeepers
PRO
427
64k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
RailsConf 2023
tenderlove
29
900
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Speed Design
sergeychernyshev
25
620
A better future with KSS
kneath
238
17k
Agile that works and the tools we love
rasmusluckow
327
21k
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