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
530
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
29
Road to k8s
bigplants
0
240
Next Level Git
bigplants
0
600
AWSを使っているならOpsWorksでDevOpsしよう!
bigplants
1
1.6k
Other Decks in Technology
See All in Technology
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
dev 補講: プロダクトセキュリティ / Product security overview
wa6sn
1
2.3k
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
940
The Rise of LLMOps
asei
7
1.4k
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
SSMRunbook作成の勘所_20241120
koichiotomo
2
130
Engineer Career Talk
lycorp_recruit_jp
0
150
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
複雑なState管理からの脱却
sansantech
PRO
1
140
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
243
12k
Practical Orchestrator
shlominoach
186
10k
A better future with KSS
kneath
238
17k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
RailsConf 2023
tenderlove
29
900
Unsuck your backbone
ammeep
668
57k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
How GitHub (no longer) Works
holman
310
140k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
How to Think Like a Performance Engineer
csswizardry
20
1.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͠Α͏