docker build battle

6247c099ad62bf727a4f9df10b6c6f23?s=47 orisano
September 03, 2018

docker build battle

6247c099ad62bf727a4f9df10b6c6f23?s=128

orisano

September 03, 2018
Tweet

Transcript

  1. Docker Build Battle Docker Meetup Tokyo #25 LT #dockertokyo @orisano

  2. Docker buildʹԿΛٻΊΔ͔

  3. buildࣗମΛߴ଎ʹʂ ग़ྗ͞ΕΔimageΛখ͘͞ʂ

  4. imageΛখ͘͢͞Δͷ͸ docker push͢Δͱ͖ͷ଎౓ docker pull͢Δͱ͖ͷ଎౓ ͷߴ଎Խʹͭͳ͕Δ

  5. ࠓ೔࿩͍ͨ͜͠ͱ

  6. ͲͷΑ͏ʹ଎͘͢Δ͔ ͲͷΑ͏ʹখ͘͢͞Δ͔

  7. ͲͷΑ͏ʹ଎͘͢Δ͔ ͲͷΑ͏ʹখ͘͢͞Δ͔

  8. ͲͷΑ͏ʹ଎͘͢Δ͔ • ίϚϯυͦͷ΋ͷΛ଎͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ • ඞཁͳ͍εςʔδΛbuild͠ͳ͍

  9. ͲͷΑ͏ʹ଎͘͢Δ͔ • ίϚϯυͦͷ΋ͷΛ଎͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ • ඞཁͳ͍εςʔδΛbuild͠ͳ͍

  10. ίϚϯυͦͷ΋ͷΛ଎͘͢Δ

  11. ଎͘Ͱ͖ΔίϚϯυ΋͋Δ

  12. Α͘ૺ۰͢Δ ଎͘Ͱ͖ΔίϚϯυ

  13. GitHub͔Β࣮ߦϑΝΠϧΛ curl or wgetͰऔಘ͢Δ

  14. GitHub Release͸S3 S3͸Rangeϔομʔ͕࢖͑Δ

  15. ͭ·Γ ฒྻμ΢ϯϩʔυ͕Մೳ

  16. github.com/orisano/rget

  17. None
  18. ؀ڥʹΑΓ·͕͢ 5min -> 2min

  19. ͲͷΑ͏ʹ଎͘͢Δ͔ • ίϚϯυͦͷ΋ͷΛ଎͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ • ඞཁͳ͍εςʔδΛbuild͠ͳ͍

  20. cacheΛޮ͔ͤΔ

  21. docker build͢ΔϚγϯ͕ ಉҰͷ৔߹ ಉҰͰͳ͍৔߹

  22. docker build͢ΔϚγϯ͕ ಉҰͷ৔߹ ಉҰͰͳ͍৔߹

  23. cacheͷ࢓૊ΈΛཧղ͢Δ

  24. RUN͸ จࣈྻ͕มΘΒͳ͍ݶΓ جຊతʹcache͞ΕΔ

  25. COPY, ADD͢ΔϑΝΠϧͷ ಺༰͕มΘͬͨ৔߹ Ҏ߱ͷRUNͷcache͕ഁغ

  26. ͳͷͰ lockfileͳͲΛઌʹίϐʔͯ͠ install͚ͩͯ͠cacheͤ͞Δ

  27. None
  28. None
  29. docker build͢ΔϚγϯ͕ ಉҰͷ৔߹ ಉҰͰͳ͍৔߹

  30. CI্Ͱbuild͢Δͱ͖ͳͲ cache͕ͳ͍͜ͱ͕ଟ͍

  31. docker save & load or docker pull docker build —cache-from

    Λ࢖͏
  32. image͕େ͖͍/layer͕ଟ͍ ৔߹ buildͷ΄͏͕ૣ͍͜ͱ΋͋Δ

  33. image͕େ͖͍/layer͕ଟ͍ ৔߹ buildͷ΄͏͕ૣ͍͜ͱ΋͋Δ ܭଌܾͯ͠ΊΔ

  34. ͲͷΑ͏ʹ଎͘͢Δ͔ • ίϚϯυͦͷ΋ͷΛ଎͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ • ඞཁͳ͍εςʔδΛbuild͠ͳ͍

  35. ґଘͷͳ͍εςʔδΛ ฒྻͰ࣮ߦ͢Δ

  36. buildkitΛ࢖͍ͬͯͩ͘͞ʂ github.com/moby/buildkit export DOCKER_BUILDKIT=1

  37. ͲͷΑ͏ʹ଎͘͢Δ͔ • ίϚϯυͦͷ΋ͷΛ଎͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ • ඞཁͳ͍εςʔδΛbuild͠ͳ͍

  38. ඞཁͳ͍εςʔδΛ build͠ͳ͍

  39. ͓ͦΒ͘buildkitͰͰ͖Δ͕ buildkit͕࢖͑ͳ͍৔߹ʹ

  40. github.com/orisano/targd • DockerfileͷASTΛऔಘ • ࢦఆ͞ΕͨεςʔδͷґଘεςʔδΛநग़ • ґଘεςʔδ͚ͩͷDockerfileΛग़ྗ

  41. github.com/orisano/targd

  42. ͲͷΑ͏ʹ଎͘͢Δ͔ ͲͷΑ͏ʹখ͘͢͞Δ͔

  43. ͲͷΑ͏ʹখ͘͢͞Δ͔ • multi stage buildΛ࢖͏ • RUNΛ·ͱΊΔ(?) • ͳͥେ͖͍͔Λ஌Δ

  44. ͲͷΑ͏ʹখ͘͢͞Δ͔ • multi stage buildΛ࢖͏ • RUNΛ·ͱΊΔ(?) • ͳͥେ͖͍͔Λ஌Δ

  45. multi stage buildΛ࢖͏

  46. multi stage buildʹ͍ͭͯ͸ ׂѪ

  47. multi stage buildͰ ͋Γ͕ͪͳٙ໰

  48. ࠷ऴతͳΠϝʔδ͕ খ͘͞ͳΔ͔Β ͦΕ·Ͱͷεςʔδ͸ ࠷దԽ͠ͳͯ͘ྑ͍ʁ

  49. None
  50. ݸਓతʹ͸No

  51. CI্Ͱbuild —cache-from Λ࢖͍ͬͯΔ৔߹ ࠷ऴεςʔδ͚ͩcache͢Δ ҙຯ͸ͳ͍

  52. moby/moby/issues/34715

  53. multi stage build࣌ʹ cacheΛޮ͔͍ͤͨ৔߹͸ લͷεςʔδ΋ ໌ࣔతʹpush͢Δ͔͠ͳ͍

  54. ݁ہpush͢ΔͷͰ push/pullͷίετ͕͔͔Δ ͢΂ͯͷεςʔδΛฏ౳ʹ খ͘͢͞΂͖ (ݸਓͷݟղͰ͢)

  55. ͲͷΑ͏ʹখ͘͢͞Δ͔ • multi stage buildΛ࢖͏ • RUNΛ·ͱΊΔ(?) • ͳͥେ͖͍͔Λ஌Δ

  56. RUNΛ·ͱΊΔ(?)

  57. ͳΜͱͳ͘RUNΛ·ͱΊΔ ͱαΠζ͕খ͘͞ͳΔ (ͱࢥ͍ͬͯ·ͨ͠)

  58. github.com/orisano/minid • DockerfileͷASTΛऔಘ • ࿈ଓ͢ΔRUN, COPY, ADD, ENVΛ࿈݁͢Δ • ݁ՌͷDockerfileΛग़ྗ

  59. github.com/orisano/minid

  60. ϨΠϠʔͷΦʔόʔϔου͕ ݮΔ͔Βখ͘͞ͳΔʁ

  61. ͍͍͑

  62. ·ͣ Ͳ͏͍͏ܗͰอଘ͞ΕͯΔ͔ Λ஌Δ

  63. aufs / overlayfs2

  64. ετϨʔδυϥΠόʔͷ ৄࡉ͸ׂѪ

  65. େࡶ೺ʹݴ͏ͱίϚϯυຖʹ fsͷࠩ෼Λ͍࣋ͬͯΔ

  66. ͳͷͰRUNΛލ͍Ͱ ಉ͡ϑΝΠϧΛ͍͡Δͱ αΠζ͕ഒʹͳͬͨΓ͢Δ

  67. RUNΛލ͍Ͱ େ͖ͳҰ࣌ϑΝΠϧΛ ࡟আͯ͠΋ޮՌ͕ͳ͍

  68. ػցతʹ RUNΛ·ͱΊΔͷ͸ ޮՌ͕͋Δ

  69. ͲͷΑ͏ʹখ͘͢͞Δ͔ • multi stage buildΛ࢖͏ • RUNΛ·ͱΊΔ(?) • ͳͥେ͖͍͔Λ஌Δ

  70. ͳͥେ͖͍͔Λ஌Δ

  71. ͍͔ͳΔνϡʔχϯάͰ΋ ܭଌͤͣʹ΍ͬͯ͸͍͚ͳ͍

  72. docker history

  73. docker history

  74. ͲͷϨΠϠʔ͕ େ͖͍͔͸Θ͔Δ͚Ͳ ͳͥେ͖͍͔͸෼͔ΓͮΒ͍

  75. github.com/orisano/dlayer • documentະ੔උ… Ӷҙ։ൃத • docker saveͰಘΒΕͨtarΛղੳ • layerͱcmdͷରԠΛͱΔ •

    layerͷࠩ෼ΛϑΝΠϧαΠζ͕େ͖͍ॱʹදࣔ
  76. github.com/orisano/dlayer

  77. ࣮ࡍʹdlayerΛ࢖ͬͯ golangެࣜalpineΠϝʔδͷ αΠζΛݮΒͯ͠Έͨ

  78. docker-library/golang/pull/232

  79. None
  80. ·ͱΊ • ίϚϯυΛ଎͘Ͱ͖ͳ͍͔ߟ͑Δ • cacheΛཧղͯ͠༗ޮʹ׆͔͢ (CI or ϩʔΧϧ) • multi

    stage buildΛ࢖͏ (ॏ͍stageΛcache͢Δ) • layerΛখ͘͢͞ΔͨΊʹ෼ੳ͢Δ • buildkitΛ࢖͏!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  81. ࡞ͬͨπʔϧ • github.com/orisano/rget • github.com/orisano/targd • github.com/orisano/minid • github.com/orisano/dlayer •

    ྑ͍ͱࢥͬͨΒελʔ͍͚ͯͨͩ͠ΔͱྭΈʹͳΓ·͢
  82. ͓͢͢Ίͷࢿྉ • https://docs.docker.com/develop/develop- images/dockerfile_best-practices/ #dockerfile-instructions • https://cloud.google.com/solutions/best- practices-for-building-containers