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
56
It's Not Ruby, But…
bryce
0
43
Ruby 2.5: What's New and What's Cool
bryce
0
57
Would You Like To Make A Game?
bryce
0
49
WebSockets and ActionCable
bryce
0
77
How I Learned to Stop Worrying and Like RSpec
bryce
0
66
How Do Computers Even Work?
bryce
1
180
Growing Distributed Systems: Abril Pro Ruby
bryce
0
45
Other Decks in Programming
See All in Programming
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
Jakarta EE meets AI
ivargrimstad
0
150
Jakarta EE meets AI
ivargrimstad
0
540
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
330
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
初めてDefinitelyTypedにPRを出した話
syumai
0
400
Featured
See All Featured
Being A Developer After 40
akosma
86
590k
4 Signs Your Business is Dying
shpigford
180
21k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Gamification - CAS2011
davidbonilla
80
5k
We Have a Design System, Now What?
morganepeng
50
7.2k
The World Runs on Bad Software
bkeepers
PRO
65
11k
A better future with KSS
kneath
238
17k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Keith and Marios Guide to Fast Websites
keithpitt
409
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