Multi-stage Builds Patterns & Practice

6247c099ad62bf727a4f9df10b6c6f23?s=47 orisano
November 21, 2018

Multi-stage Builds Patterns & Practice

6247c099ad62bf727a4f9df10b6c6f23?s=128

orisano

November 21, 2018
Tweet

Transcript

  1. Multi-stage Builds Patterns & Practice Docker Meetup Tokyo #26 #dockertokyo

    @orisano
  2. ࣗݾ঺հ • @orisano • ۦ͚ग़͠ͷΞϓϦέʔγϣϯΤϯδχΞ • ޮ཰తͳdocker buildΛ໨ࢦͯ͠ؤு͍ͬͯΔ

  3. օ͞Μ Multi-stage Builds ͯ͠·͔͢ʁ

  4. ͦ΋ͦ΋ Multi-stage Builds ͱ͸

  5. Docker 17.05 (2017-05-04) ͔Βೖͬͨػೳ

  6. Docker 17.05 (2017-05-04) ͔Βೖͬͨػೳ

  7. എܠ

  8. ͦ΋ͦ΋ push͢ΔΠϝʔδΛ খ͍ͨ͘͞͠

  9. Multi-stage BuildsҎલ

  10. build༻ͷDockerfileΛ࢖ͬͯ buildͯ͠volume͔Β ੒Ռ෺ΛऔΓग़͢

  11. Ұ࿈ͷྲྀΕΛ shell scriptͰॻ͍͍ͯͨ $ ./build.sh

  12. ͜ΕΛDockerfileͷΈͰ ࣮ݱͰ͖ΔΑ͏ʹͳͬͨ

  13. ෳ਺ͷFROM COPY —from ͰͷผΠϝʔδ͔Βͷίϐʔ

  14. ্ͷΑ͏ͳഎܠͰ௥Ճ͞Εͨ Multi-stage Builds

  15. ࢖͑Δ΋ͷ͸࢖͏ͷ͕ਓؒ

  16. ͍ΖΜͳ׆༻ํ๏͕͋Δ

  17. https://medium.com/@tonistiigi/advanced- multi-stage-build-patterns-6f741b852fae

  18. https://speakerdeck.com/ garethr/advanced-docker- image-build-patterns (2019-11-01 Velocity)

  19. Multi-stage Builds Patterns

  20. builder & app alias image tested app inner base image

    split step
  21. builder & app alias image tested app inner base image

    split step
  22. None
  23. #VJMEFS "QQ

  24. builder & app alias image tested app inner base image

    split step
  25. None
  26. base imageΛ ໌ࣔతʹڞ௨ԽͰ͖Δ

  27. builder & app alias image tested app inner base image

    split step
  28. None
  29. #VJMEFS "QQ 5FTU

  30. None
  31. #VJMEFS "QQ 5FTU

  32. builder & app alias image tested app inner base image

    split step
  33. None
  34. #BTF "QQ "QQ

  35. builder & app alias image tested app inner base image

    split step
  36. None
  37. 'BU#VJMEFS "QQ

  38. #VJMEFS "QQ 7FOEPS )FBWZ )FBWZ

  39. cacheΛ࠷େݶ׆༻Ͱ͖Δ

  40. Multi-stage Builds͸ buildkitͱ૬ੑ͕ྑ͍

  41. ฒྻbuildʹΑΔ ߴ଎Խ͕ݟࠐΊΔʂ

  42. Multi-stage builds͸࠷ߴʂ

  43. ͔͠͠

  44. buildkit͡Όͳ͍ͱਏ͍

  45. CI͸buildkit ࢖͑ͳ͔ͬͨΓ͢Δ

  46. CI্ͷ Multi-stage Buildsͷ cacheઓུ

  47. ͜Ε·Ͱͷ΍Γํͩͱ খ͍͞ΠϝʔδͷcacheΛ ͯ͠͠·͏

  48. ຊ౰ʹඞཁͳͷ͸ ॏ͍Πϝʔδͷcache

  49. CIʹ͓͚Δ Multi-stage Builds͸ ΄΅͢΂ͯͷεςʔδΛ ໌ࣔతʹbuild͢Δ͔͠ͳ͍

  50. ͦͷ্Ͱ Ͳ͏͍͏ઓུΛऔΔ͔

  51. save & load Or push & pull + —cache-from

  52. save & load ͷ৔߹

  53. Pros ֎෦ʹstorage͕͋Ε͹ ࣮ݱՄೳ ϑΝΠϧड͚౉͠ͷΈͰྑ͍

  54. Cons αΠζ͕Ͱ͔͍ ಉ͡ϕʔεΠϝʔδͰ΋ॏෳ save͕ͳΜ͔ॏ͍

  55. push & pull ͷ৔߹

  56. Pros Registry͕͋Ε͹Մೳ ѹॖ͞Εͨঢ়ଶͰड͚౉͠ ϕʔεΠϝʔδ͕ॏෳ͠ͳ͍

  57. Cons cache༻tag or image͕ඞཁ push & pullͷෛՙ

  58. ͿͬͪΌ͚ݱঢ়Ͱ͸ CI্ͷcache͕໘౗ष͗͢Δ

  59. CIͰ cacheΛޮ͔͍ͤͨͳΒ 2 stage·Ͱ (ݸਓͷײ૝Ͱ͢)

  60. CIͱͷ૬ੑ΋͋Δ͕ pipeline͕ෳࡶʹͳͬͨΓ ͦ΋ͦ΋࣮ݱͰ͖ͳ͔ͬͨΓ

  61. Multi-stage Buildsͷ࢖͍ॴ

  62. buildΑΓpullͷ΄͏͕ଟ͍ dockerd͕มΘΒͳ͍؀ڥ खݩͰͷbuildޮ཰Λ࠷େԽ

  63. CI޲͖Ͱ͸ͳ͍

  64. ͦΕͰ΋΍Γ͍ͨਓͷͨΊʹ

  65. ࡞Γ·ͨ͠ orisano/castage

  66. None
  67. DockerfileΛಡΜͰ͖ͯ ͢΂ͯͷεςʔδΛநग़ pull ͱ cache-fromΛ ࣗಈੜ੒ͯ͘͠ΕΔ

  68. None
  69. None
  70. ͜Ε͚ͩͰ͸ղܾ͠ͳ͍

  71. dockerdͱbuildkit —cache-from ͷڍಈ͕ҧ͏

  72. ͳ͍৔߹͸ ແࢹͯ͘͠Εͨ΄͏͕خ͍͠

  73. ॳظΠϝʔδ͕ͳ͍࣌ ͚ͩpipelineΛม͑Δͷਏ͍

  74. ݁࿦

  75. CIʹ͓͚Δ Multi-stage Builds͸೉͍͠