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
99
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
90
Rails and the Internet of Things
bryce
1
57
It's Not Ruby, But…
bryce
0
47
Ruby 2.5: What's New and What's Cool
bryce
0
59
Would You Like To Make A Game?
bryce
0
50
WebSockets and ActionCable
bryce
0
77
How I Learned to Stop Worrying and Like RSpec
bryce
0
69
How Do Computers Even Work?
bryce
1
180
Growing Distributed Systems: Abril Pro Ruby
bryce
0
46
Other Decks in Programming
See All in Programming
為你自己學 Python
eddie
0
520
ISUCON14感想戦で85万点まで頑張ってみた
ponyo877
1
590
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
930
Androidアプリの One Experience リリース
nein37
0
1.1k
テストコード書いてみませんか?
onopon
2
340
AHC041解説
terryu16
0
360
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
1.4k
Fixstars高速化コンテスト2024準優勝解法
eijirou
0
190
AWS re:Invent 2024個人的まとめ
satoshi256kbyte
0
100
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
250
BEエンジニアがFEの業務をできるようになるまでにやったこと
yoshida_ryushin
0
190
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
430
Featured
See All Featured
Being A Developer After 40
akosma
89
590k
The Cult of Friendly URLs
andyhume
78
6.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
360
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
30
2.1k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
192
16k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
Agile that works and the tools we love
rasmusluckow
328
21k
Why Our Code Smells
bkeepers
PRO
335
57k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.1k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
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