Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails on Docker

Rails on Docker

2018/5/10の表参道.rbで発表した資料です。
#omotesandorb

0e7a809ed12558c5b148331d1a703ccb?s=128

Daiki Hirakata

May 10, 2018
Tweet

Transcript

  1. Rails on Docker @bigplants May 10th 2018 @Omotesando.rb

  2. Who am I ? • Daiki Hirakata (36) • Software

    Engineer • Main Programing Languages:
 PHP, Ruby • Primary interests:
 DevOps, Docker, Kubernetes, Microservice Architecture, GCP @bigplants
  3. ࠷ۙϥϯχϯά͸͡Ί·ͨ͠

  4. ͪΐͬͱ͚ͩએ఻

  5. ઈࢍ։ൃऀืूதʂ • ϓϩμΫτ໊: ALL-IN • اۀ׆ಈͰඞཁͳશͯͷ πʔϧ͕ೖ͍ͬͯΔ • Rails, Angular,

    AWS • גࣜձࣾϏδωεόϯΫ άϧʔϓ
  6. ݱࡏɺεςʔδϯά؀ڥΛ ઈࢍKubernetesҠߦதͰ͢ɻ

  7. ϩʔυϚοϓ • ։ൃ༻ίϯςφ४උ • ެ։༻ίϯςφ४උ • GKEʹσϓϩΠ <- ΠϚίί •

    CI/CDύΠϓϥΠϯͷ੔උ
 ͍ͭͰ΋୭Ͱ΋͓खܰʹk8sΫϥελʹ؀ڥߏங&σ ϓϩΠͰ͖ΔΑ͏ʹ͢Δ
  8. ໨ࢦͤʂ ແݶεςʔδϯάͷ࣮ݱʂ

  9. ࠓ೔͸ެ։؀ڥ༻ͷ Rails on Docker ͳ࿩Λ͠·͢ɻ × ΄΅dockerͷ࿩Ͱ͢ɻɻ

  10. Rails appΛ docker build͢Δͱ͖

  11. ݁ߏ΍Δ͜ͱ͋Δ • bundle install • npm install • rake bower:install

    • rake bower:resolve • rake assets:precompile • And more tasks…
  12. ނʹɺdocker buildʹ ͔͔࣌ؒΔ Լख͢Δͱover 10min

  13. ߋʹΠϝʔδαΠζͷංେԽ Լख͢Δͱover 1.5GB

  14. docker build͸1secͰ΋ૣ͍ ΄͏͕͍͍ git pushͷ౓ʹCIʹdocker build͍ͤͨ͞

  15. docker image͸1MBͰ΋ܰ ͍΄͏͕͍͍ Google Container Registory΁ͷ ΞοϓϩʔυɺGKE΁ͷσϓϩΠʹӨڹ͢Δ

  16. docker build docker push git push kubectl apply get image

  17. docker build docker push git push kubectl apply get image

    Ϗϧυʹ͔͔࣌ؒΔͱ
  18. docker build docker push git push kubectl apply get image

    ΠϝʔδͷαΠζ͕σΧΠͱ
  19. Ϗϧυͷ࣌ؒΛ୹ॖ͢Δʹ͸ʁ

  20. ΩϟογϡΛ͏·͔ͭ͘͏

  21. None
  22. ΠϝʔδͷαΠζΛ཈͑Δʹ ͸

  23. ·ͣඞཁͳ΋ͷΛશ෦ೖΕΔ

  24. ཁΒͳ͍΋ͷΛ࡟আ ಉ͡Dockerfile಺

  25. ΋͏Ұ౓ίϐʔ ಉ͡Dockerfile಺

  26. ͜ΕͰΠϝʔδͷαΠζ͕ 1.5GB -> 500MB͘Β͍ʹʂ ※͋͘·Ͱචऀͷ؀ڥͰͷ࿩Ͱ͢

  27. Tips

  28. docker buildͰ؀ڥม਺Λॻ ͖׵͑Δʹ͸

  29. docker buildͰ͸ENVΛ౉ͤͳ ͍

  30. --build-arg͕࢖͑ͦ͏

  31. ARGͰENVΛॻ͖׵͑Δ • docker build --build-arg RAILS_ENV=production --build-arg HOGE=fuga

  32. ARGͷҐஔ΋ॏཁ

  33. ARGͷҐஔ΋ॏཁ

  34. RUN಺Ͱ؀ڥม਺Λૢ࡞͢Δ΂ ͖Ͱͳ͍ • ͨͩͷshellͩͱ͍͏ࣄΛཧղ͢Δ

  35. ϨΠϠ͕෼͔ΕΔͱͦΕͧΕ༰ྔΛ৯͏ɻͳΔ΂͘RUN͸·ͱΊΔ ͋ͱ͔Β࡟আͯ͠΋Πϝʔδα Πζ͸มΘΒͳ͍

  36. ΋͘͠͸ɺ͖ͬ͞ग़͖ͯͨ Multi-stage buildͷςΫχο ΫͰ

  37. docker history <image>ͰͲ ͜ͰαΠζ͕๲ΒΜͰΔ͔֬ೝ

  38. σόοάͷͨΊʹ͍Βͳ͍΋ͷΛ࡟আ͢Δ લͷঢ়ଶͰ֬ೝͰ͖ΔΑ͏ʹεςʔδΛΘ ͚Δ • docker build --target <stage name> -t

    <tag>
  39. ࠓ೔ͷ·ͱΊ • Ϗϧυߴ଎ԽͷҝʹΩϟογϡΛ͏·͘࢖͓ ͏ • ΠϝʔδαΠζͷѹॖͷͨΊʹMulti-stage build͠Α͏