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
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
420
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
500
gopls を改造したら開発生産性が高まった
satorunooshie
8
260
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
460
推し活の ハイトラフィックに立ち向かう Railsとアーキテクチャ - Kaigi on Rails 2024
falcon8823
6
2.4k
Identifying User Idenity
moro
6
8.7k
カラム追加で増えるActiveRecordのメモリサイズ イメージできますか?
asayamakk
4
1.7k
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
450
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
320
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.6k
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
240
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.6k
Agile that works and the tools we love
rasmusluckow
327
21k
Fireside Chat
paigeccino
32
3k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Why Our Code Smells
bkeepers
PRO
334
57k
Become a Pro
speakerdeck
PRO
24
5k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Music & Morning Musume
bryan
46
6.1k
Bash Introduction
62gerente
608
210k
Raft: Consensus for Rubyists
vanstee
136
6.6k
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