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
docker for rubyists
Search
Bryce "BonzoESC" Kerley
October 17, 2017
Programming
0
98
docker for rubyists
miamirb 10/16/2017
Bryce "BonzoESC" Kerley
October 17, 2017
Tweet
Share
More Decks by Bryce "BonzoESC" Kerley
See All by Bryce "BonzoESC" Kerley
Ruby in 2020
bryce
1
87
Rails and the Internet of Things
bryce
1
54
It's Not Ruby, But…
bryce
0
42
Ruby 2.5: What's New and What's Cool
bryce
0
56
Would You Like To Make A Game?
bryce
0
49
WebSockets and ActionCable
bryce
0
72
How I Learned to Stop Worrying and Like RSpec
bryce
0
66
How Do Computers Even Work?
bryce
1
170
Growing Distributed Systems: Abril Pro Ruby
bryce
0
45
Other Decks in Programming
See All in Programming
型付きで行うVSCode拡張機能開発 / VSCode Meetup #31
mazrean
0
240
複数プロダクトの技術改善・クラウド移行に向き合うチームのフレキシブルなペア・モブプログラミングの実践 / Flexible Pair Programming And Mob Programming
honyanya
0
230
(Deep|Web) Link support with expo-router
mrtry
0
170
ビット演算の話 / Let's play with bit operations
kaityo256
PRO
4
180
4年間変わらなかった YOUTRUSTのアーキテクチャ
daiki1003
1
610
[PHPカンファレンス沖縄2024]「無理なくできるだけ安全に」テストもないレガシーコードをリファクタリングするテクニック
ikezoemakoto
3
130
Cloud Adoption Framework にみる組織とクラウド導入戦略
tomokusaba
2
460
선언형 UI를 학습할 때 알아둬야하는 키워드들
l2hyunwoo
0
140
How to debug Xdebug... or any other weird bug in PHP
dunglas
1
590
コードレビューと私の過去と未来
jxmtst
0
280
UnJSで簡単に始めるCLIツール開発 / cli-tool-development-with-unjs
aoseyuu
2
290
CSC509 Lecture 04
javiergs
PRO
0
140
Featured
See All Featured
Ruby is Unlike a Banana
tanoku
96
11k
Learning to Love Humans: Emotional Interface Design
aarron
272
40k
Designing on Purpose - Digital PM Summit 2013
jponch
114
6.9k
Fireside Chat
paigeccino
32
3k
A Tale of Four Properties
chriscoyier
156
22k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
The Language of Interfaces
destraynor
154
24k
Making Projects Easy
brettharned
115
5.9k
Optimizing for Happiness
mojombo
375
69k
BBQ
matthewcrist
85
9.2k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.5k
In The Pink: A Labor of Love
frogandcode
139
22k
Transcript
Docker for Rubyists Miami Ruby Brigade Oct. 16, 2017
Rails in 2005 • Compile Ruby from source • Install
Rubygems separately • Choose your own adventure: • CGI (slow) • FastCGI (quite miserable to set up) • App server (fast, low-grade miserable to set up) • Configure database • Figure out gem dependencies
Rails in 2017 • Choose your own install Ruby adventure
• rbenv • chruby • rvm • PPA • source • Configure database • Install dependencies
Better, Not Great • lotta configuration • need to script
it • ideally dev and prod are same
Configuration Management • Makes setting stuff up repeatable • Good
for production • Less-good for development
Vagrant • Makes setting up a VM repeatable • Good
but slow for development • Less common in production
Docker • Good for development • Good and common in
production • Plenty fast • Lots of work is done
Let's Dockerize Greatjobify
None
Greatjobify • Sinatra • ImageMagick
Greatjobify 1. Pick base image 2. Add OS packages 3.
Create and change to app directory 4. Add Gemfile and Gemfile.lock 5. Bundle 6. Add rest of app 7. Run it
Dockerfile FROM ruby:2.4.1 RUN apt-get update -qq && \
apt-get install -y build-essential imagemagick RUN mkdir /greatjobify WORKDIR /greatjobify ADD Gemfile* /greatjobify/ RUN bundle install ADD . /greatjobify EXPOSE 9292 CMD ["unicorn", "-p", "9292"]
Dockerfile FROM ruby:2.4.1 RUN apt-get update -qq && \
apt-get install -y build-essential imagemagick RUN mkdir /greatjobify WORKDIR /greatjobify ADD Gemfile* /greatjobify/ RUN bundle install ADD . /greatjobify EXPOSE 9292 CMD ["unicorn", "-p", "9292"] Base image
None
Dockerfile FROM ruby:2.4.1 RUN apt-get update -qq && \
apt-get install -y build-essential imagemagick RUN mkdir /greatjobify WORKDIR /greatjobify ADD Gemfile* /greatjobify/ RUN bundle install ADD . /greatjobify EXPOSE 9292 CMD ["unicorn", "-p", "9292"] OS packages
Dockerfile FROM ruby:2.4.1 RUN apt-get update -qq && \
apt-get install -y build-essential imagemagick RUN mkdir /greatjobify WORKDIR /greatjobify ADD Gemfile* /greatjobify/ RUN bundle install ADD . /greatjobify EXPOSE 9292 CMD ["unicorn", "-p", "9292"] Create and change to app directory
Dockerfile FROM ruby:2.4.1 RUN apt-get update -qq && \
apt-get install -y build-essential imagemagick RUN mkdir /greatjobify WORKDIR /greatjobify ADD Gemfile* /greatjobify/ RUN bundle install ADD . /greatjobify EXPOSE 9292 CMD ["unicorn", "-p", "9292"] Add Gemfile and Gemfile.lock
Dockerfile FROM ruby:2.4.1 RUN apt-get update -qq && \
apt-get install -y build-essential imagemagick RUN mkdir /greatjobify WORKDIR /greatjobify ADD Gemfile* /greatjobify/ RUN bundle install ADD . /greatjobify EXPOSE 9292 CMD ["unicorn", "-p", "9292"] Bundle
Dockerfile FROM ruby:2.4.1 RUN apt-get update -qq && \
apt-get install -y build-essential imagemagick RUN mkdir /greatjobify WORKDIR /greatjobify ADD Gemfile* /greatjobify/ RUN bundle install ADD . /greatjobify EXPOSE 9292 CMD ["unicorn", "-p", "9292"] Add rest of the app
Dockerfile FROM ruby:2.4.1 RUN apt-get update -qq && \
apt-get install -y build-essential imagemagick RUN mkdir /greatjobify WORKDIR /greatjobify ADD Gemfile* /greatjobify/ RUN bundle install ADD . /greatjobify EXPOSE 9292 CMD ["unicorn", "-p", "9292"] Declare a listening port
Dockerfile FROM ruby:2.4.1 RUN apt-get update -qq && \
apt-get install -y build-essential imagemagick RUN mkdir /greatjobify WORKDIR /greatjobify ADD Gemfile* /greatjobify/ RUN bundle install ADD . /greatjobify EXPOSE 9292 CMD ["unicorn", "-p", "9292"] Command to run
Dockerfile FROM ruby:2.4.1 RUN apt-get update -qq && \
apt-get install -y build-essential imagemagick RUN mkdir /greatjobify WORKDIR /greatjobify ADD Gemfile* /greatjobify/ RUN bundle install ADD . /greatjobify EXPOSE 9292 CMD ["unicorn", "-p", "9292"]
Building the Image docker build -t greatjobify . Name it
"greatjobify"
None
None
And there it is
Running it docker run --rm -p 9292:9292 -it greatjobify Remove
the instance afterwards Forward instance port 9292 to host port 9292 Keep stdio open and hook it up here The image to run
tfw you don't update your apps more than a couple
times per decade
None
None
External Services greatjobify has an optional dependency on memcache
External Services • Instances can run multiple processes • Instances
should be single-purpose • Horizontal scalability • Orchestrate several instances to work together
Docker Compose "Orchestration"
docker-compose.yml • Describe each instance that you need • base
image or build directory • mounted volumes • dependencies • open ports • commands • environment variables
None
web.rb (snippet) memcache_address = ENV['MEMCACHIER_SERVERS'] || 'localhost:11211' memcache =
[ memcache_address, { username: ENV['MEMCACHIER_USERNAME'] || nil, password: ENV['MEMCACHIER_PASSWORD'] || nil } ] dalli = Dalli::Client.new *memcache use Rack::Cache, :metastore => dalli, :entitystore => dalli
docker-compose.yml • Web service • Build the current directory •
Expose 9292 • Depend on memcached service • Set MEMCACHIER_SERVERS environment variable • Memcached service • Use the "memcached" image
docker-compose.yml version: '3' services: web: build: .
ports: - "9292:9292" depends_on: - memcached environment: - MEMCACHIER_SERVERS=memcached memcached: image: memcached
Running It docker-compose up
None
None
None
None
None
Rails App • Similar to Sinatra • Web process •
Db processes • Support processes • Database console • App console
Docker in Production • Google Container Engine • AWS Elastic
beanstalk • Heroku Container Registry
Docker in Production • Docker Swarm • Kubernetes