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
Rails on Docker
Search
Daiki Hirakata
May 10, 2018
Technology
2
540
Rails on Docker
2018/5/10の表参道.rbで発表した資料です。
#omotesandorb
Daiki Hirakata
May 10, 2018
Tweet
Share
More Decks by Daiki Hirakata
See All by Daiki Hirakata
Firestoreコスト圧縮の旅
bigplants
0
35
Road to k8s
bigplants
0
250
Next Level Git
bigplants
0
610
AWSを使っているならOpsWorksでDevOpsしよう!
bigplants
1
1.6k
Other Decks in Technology
See All in Technology
Building Products in the LLM Era
ymatsuwitter
10
5k
Googleマップ/Earthが一般化した 地図タイルのイマ
mapconcierge4agu
1
200
『衛星データ利用の方々にとって近いようで触れる機会のなさそうな小話 ~ 衛星搭載ソフトウェアと衛星運用ソフトウェア (実物) を動かしながらわいわいする編 ~』 @日本衛星データコミニティ勉強会
meltingrabbit
0
140
AndroidデバイスにFTPサーバを建立する
e10dokup
0
240
Cloud Spanner 導入で実現した快適な開発と運用について
colopl
1
320
滅・サービスクラス🔥 / Destruction Service Class
sinsoku
6
1.6k
Larkご案内資料
customercloud
PRO
0
650
飲食店予約台帳を支えるインタラクティブ UI 設計と実装
siropaca
7
1.6k
モノレポ開発のエラー、誰が見る?Datadog で実現する適切なトリアージとエスカレーション
biwashi
6
790
Helm , Kustomize に代わる !? 次世代 k8s パッケージマネージャー Glasskube 入門 / glasskube-entry
parupappa2929
0
210
Tech Blogを書きやすい環境づくり
lycorptech_jp
PRO
1
230
関東Kaggler会LT: 人狼コンペとLLM量子化について
nejumi
3
540
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
BBQ
matthewcrist
86
9.5k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
Thoughts on Productivity
jonyablonski
69
4.5k
A better future with KSS
kneath
238
17k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.8k
Rails Girls Zürich Keynote
gr2m
94
13k
Testing 201, or: Great Expectations
jmmastey
42
7.2k
Optimizing for Happiness
mojombo
376
70k
Writing Fast Ruby
sferik
628
61k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
Transcript
Rails on Docker @bigplants May 10th 2018 @Omotesando.rb
Who am I ? • Daiki Hirakata (36) • Software
Engineer • Main Programing Languages: PHP, Ruby • Primary interests: DevOps, Docker, Kubernetes, Microservice Architecture, GCP @bigplants
࠷ۙϥϯχϯά͡Ί·ͨ͠
ͪΐͬͱ͚ͩએ
ઈࢍ։ൃऀืूதʂ • ϓϩμΫτ໊: ALL-IN • اۀ׆ಈͰඞཁͳશͯͷ πʔϧ͕ೖ͍ͬͯΔ • Rails, Angular,
AWS • גࣜձࣾϏδωεόϯΫ άϧʔϓ
ݱࡏɺεςʔδϯάڥΛ ઈࢍKubernetesҠߦதͰ͢ɻ
ϩʔυϚοϓ • ։ൃ༻ίϯςφ४උ • ެ։༻ίϯςφ४උ • GKEʹσϓϩΠ <- ΠϚίί •
CI/CDύΠϓϥΠϯͷඋ ͍ͭͰ୭Ͱ͓खܰʹk8sΫϥελʹڥߏங&σ ϓϩΠͰ͖ΔΑ͏ʹ͢Δ
ࢦͤʂ ແݶεςʔδϯάͷ࣮ݱʂ
ࠓެ։ڥ༻ͷ Rails on Docker ͳΛ͠·͢ɻ × ΄΅dockerͷͰ͢ɻɻ
Rails appΛ docker build͢Δͱ͖
݁ߏΔ͜ͱ͋Δ • bundle install • npm install • rake bower:install
• rake bower:resolve • rake assets:precompile • And more tasks…
ނʹɺdocker buildʹ ͔͔࣌ؒΔ Լख͢Δͱover 10min
ߋʹΠϝʔδαΠζͷංେԽ Լख͢Δͱover 1.5GB
docker build1secͰૣ͍ ΄͏͕͍͍ git pushͷʹCIʹdocker build͍ͤͨ͞
docker image1MBͰܰ ͍΄͏͕͍͍ Google Container Registoryͷ ΞοϓϩʔυɺGKEͷσϓϩΠʹӨڹ͢Δ
docker build docker push git push kubectl apply get image
docker build docker push git push kubectl apply get image
Ϗϧυʹ͔͔࣌ؒΔͱ
docker build docker push git push kubectl apply get image
ΠϝʔδͷαΠζ͕σΧΠͱ
Ϗϧυͷ࣌ؒΛॖ͢Δʹʁ
ΩϟογϡΛ͏·͔ͭ͘͏
None
ΠϝʔδͷαΠζΛ͑Δʹ
·ͣඞཁͳͷΛશ෦ೖΕΔ
ཁΒͳ͍ͷΛআ ಉ͡Dockerfile
͏Ұίϐʔ ಉ͡Dockerfile
͜ΕͰΠϝʔδͷαΠζ͕ 1.5GB -> 500MB͘Β͍ʹʂ ※͋͘·ͰචऀͷڥͰͷͰ͢
Tips
docker buildͰڥมΛॻ ͖͑Δʹ
docker buildͰENVΛͤͳ ͍
--build-arg͕͑ͦ͏
ARGͰENVΛॻ͖͑Δ • docker build --build-arg RAILS_ENV=production --build-arg HOGE=fuga
ARGͷҐஔॏཁ
ARGͷҐஔॏཁ
RUNͰڥมΛૢ࡞͢Δ ͖Ͱͳ͍ • ͨͩͷshellͩͱ͍͏ࣄΛཧղ͢Δ
ϨΠϠ͕͔ΕΔͱͦΕͧΕ༰ྔΛ৯͏ɻͳΔ͘RUN·ͱΊΔ ͋ͱ͔Βআͯ͠Πϝʔδα ΠζมΘΒͳ͍
͘͠ɺ͖ͬ͞ग़͖ͯͨ Multi-stage buildͷςΫχο ΫͰ
docker history <image>ͰͲ ͜ͰαΠζ͕ΒΜͰΔ͔֬ೝ
σόοάͷͨΊʹ͍Βͳ͍ͷΛআ͢Δ લͷঢ়ଶͰ֬ೝͰ͖ΔΑ͏ʹεςʔδΛΘ ͚Δ • docker build --target <stage name> -t
<tag>
ࠓͷ·ͱΊ • ϏϧυߴԽͷҝʹΩϟογϡΛ͏·͓͘ ͏ • ΠϝʔδαΠζͷѹॖͷͨΊʹMulti-stage build͠Α͏