Build Containers with Dockerfile Best Practicies

Build Containers with Dockerfile Best Practicies

Ad22fcf5773b906c08330f4d57242212?s=128

Kohei Ota

May 13, 2019
Tweet

Transcript

  1. +BQBO$POUBJOFS%BZTͰ ࡞ͬͨެࣜσϞΞϓϦͷ %PDLFSpMFʹ͍ͭͯʢԾʣ !JOEVDUPS $POUBJOFS#VJME.FFUVQ

  2. +BQBO$POUBJOFS%BZTͰ ࡞ͬͨެࣜσϞΞϓϦͷ %PDLFSpMFʹ͍ͭͯʢԾʣ !JOEVDUPS $POUBJOFS#VJME.FFUVQ

  3. ࠓ೔͸ͦΜͳ࿩͸ʢ΄΅ʣ Ұ੾͠ͳ͍Ͱ͢

  4. ϕετϓϥΫςΟεʹԊͬͯɺ %PDLFSpMFͷՄಡੑͱ ΩϟογϡɺΠϝʔδͷαΠζͷ ઓུʹ͍ͭͯߟ͑ͯΈͨ !JOEVDUPS $POUBJOFS#VJME.FFUVQ

  5. ࣗݾ঺հ w JOEVDUPS w %PDLFS.FFUVQ5PLZP0SHBOJ[FS ࿬໾  w %PDLFSpMFͱӳޠ͕޷͖ w

    কདྷͷເ͸೦͚ͨͩ͡Ͱαʔόʔ͕͍͍ײ͡ʹ্ཱ͕ͪΔ Α͏ʹͳΔ͜ͱ
  6. %PDLFSCVJMEͯ͠·͔͢ʁ

  7. %PDLFSSVOͯ͠·͔͢ʁ

  8. %PDLFSSVOͯ͠·͔͢ʁ

  9. %PDLFSpMFͷϕετϓϥΫςΟε ͝ଘ஌Ͱ͔͢ʁ

  10. IUUQTXXXTMJEFTIBSFOFU %PDLFSEDTGEPDLFSpMFCFTU QSBDUJDFT

  11. %PDLFS$PO 4BO'SBODJTDPͰൃද͞Εͨࢿྉ

  12. w Ϗϧυ࣌ؒ w ΠϝʔδαΠζ w ϝϯςφϯεੑ w ηΩϡϦςΟ w ࣋ଓੑ࠶ݱੑ

  13. %PDLFSCVJMEͷ͓೰ΈϙΠϯτ w ΠϝʔδαΠζ w Ϗϧυͷ଎͞ w Մಡੑͱϝϯςφϯεੑ w ࠶ݱੑ w

    ηΩϡϦςΟ
  14. %PDLFSCVJMEͷ͓೰ΈϙΠϯτ w ΠϝʔδαΠζˡ w Ϗϧυͷ଎͞ w Մಡੑͱϝϯςφϯεੑ w ࠶ݱੑ w

    ηΩϡϦςΟ
  15. ΠϝʔδαΠζ͸૿͑Δ w %PDLFSΠϝʔδΛӡ༻͍ͯ͠ΔͱɺαΠζͷංେԽ͸ආ͚ ΒΕͳ͍໰୊ w ύοέʔδͷ௥Ճ w ΞϓϦέʔγϣϯґଘͷϥΠϒϥϦͷ௥Ճ w ಺แ͓͖͍ͯͨ͠όΠφϦϑΝΠϧͷ௥ՃͳͲͳͲ

  16. ΠϝʔδαΠζΛ཈͑ΔऔΓ૊Έ ͦͷܰྔͳϕʔεΠϝʔδΛ࢖͏

  17. ϕʔεΠϝʔδͷ࿩ ద౰ ΠϝʔδαΠζ ൚༻ੑ ॊೈੑ ֦ுੑ རศੑ %FCJBO TMJN ☓

    ˚ ˕ ˕ ˕ ˕ ˑ ˑ "MQJOF ˕ ˓ MJCD͕ʜ ˓ ˕ #VTZCPY ˑ ˚ ˚ ˓ 4DSBUDI ☠ ʁʁʁʁ ☓ 㱣
  18. ϕʔεΠϝʔδͷબఆ w جຊɺΠϝʔδαΠζ͸ؾʹ͢Δ΂͖ w ͱ͸͍͑ɺϥΠϒϥϦͷґଘؔ܎͕ਂ͘ͳͬͯ͠·͏৔߹ɺ
 Πϝʔδͷӡ༻ίετ্͕͕ͬͯ͠·͏ͷͰແཧ͠ͳ͍ํ͕
 ྑ͍͜ͱ΋ଟ͍ w ׳Εͳ͍͏ͪ͸"MQJOFΛແཧʹ࢖͏ඞཁ͸ͳ͍ͱ͸ࢥ͏

  19. ΠϝʔδαΠζΛ཈͑ΔऔΓ૊Έ ͦͷNVMUJTUBHFCVJMEΛ࢖͏

  20. NVMUJTUBHFCVJMEͱ͸ w ಉҰ%PDLFSpMFͷதͰʮผͷϏϧυͷॲཧʯΛݺͼग़͢࢓૊Έ w ྫ HPͷΠϝʔδͰίϯύΠϧͨ͠HPͷόΠφϦΛ/PEFKTͷίϯςφ ʹ৐ͤͨΓͰ͖Δ w ͭͷΠϝʔδʹෳ਺ͷΞϓϦέʔγϣϯґଘύοέʔδΛೖΕΔඞ ཁ͕ͳ͘ͳΔͷͰɺΠϝʔδαΠζ΋μ΢ϯ

    w %PDLFSpMFͷதͰෳ਺ճ'30.Λॻ͘ͱ࣮ݱͰ͖Δ
  21. NVMUJTUBHFCVJMEͱ͸ IVHPͷ$-*Λ%-ͯ͘͠Δεςʔδ औಘͨ͠όΠφϦΛ/PEFͷΠϝʔδʹೖΕΔ XHFUͱ͔DBDFSUJpDBUFTͱ͔͸ΞϓϦͷ ίϯςφʹ࢒Βͳ͍

  22. ΠϝʔδαΠζΛ཈͑ΔऔΓ૊Έ ͦͷΞϓϦέʔγϣϯͷಈ࡞ʹ ؔ܎ͷͳ͍ϑΝΠϧΛऔΓࠐ·ͳ͍

  23. Ͳ͏͍͏͜ͱ͔ w HJU഑ԼͷϑΝΠϧ͸EPDLFSJHOPSF͢Δ w ίϯύΠϧܕݴޠͷ৔߹ɺιʔείʔυ͸͍Βͳ͍ w ྫHPͳΒόΠφϦɺKBWBͳΒXBSKBS͚͕ͩ͋Ε͹ྑ͍ w ϓϩμΫγϣϯϏϧυΛਖ਼͘͠࢖͏ w

    ྫ։ൃ༻ϥΠϒϥϦ͸Πϝʔδͷதʹ͸औΓࠐ·ͳ͍ w ΤσΟλ΍σόοάπʔϧ΋جຊ͸ೖΕͳ͍
  24. ΞηοτͷίϯύΠϧʹ࢖ͬͨ ϥΠϒϥϦΛফͯ͠ɺ ϓϩμΫγϣϯʹඞཁͳ ґଘؔ܎ΛೖΕ௚͢ ͍ܰͷͰBMQJOFϕʔεʹ͢Δ ίϯύΠϧͷͱ͖BMQJOFͩͱͭΒΈ ͕ਂ͍ͷͰɺϝϯςੑΛߟྀͯ͠ EFCJBOϕʔεͰίϯύΠϧ͢Δ

  25. %PDLFSCVJMEͷ͓೰ΈϙΠϯτ w ΠϝʔδαΠζ w Ϗϧυͷ଎͞ˡ w Մಡੑͱϝϯςφϯεੑ w ࠶ݱੑ w

    ηΩϡϦςΟ
  26. Ϗϧυͷ଎౓Λ্͛Δཁૉ w ϏϧυΩϟογϡΛޮ͔ͤΔ w ฒྻੑΛ্͛Δ w Ͱ͖ΔݶΓڞ௨ͷϕʔεΠϝʔδΛ࢖͏

  27. %PDLFSpMFͷΩϟογϡ w มߋස౓͕௿͍͕ॲཧʹ͕͔͔࣌ؒΔ΋ͷΛ্ʹدͤΔ w ύοέʔδϚωʔδϟͱ͔ɺMPDLϑΝΠϧͷ$01:΋্ʹدͤΔ w ύοέʔδͷΠϯετʔϧͱΞοϓσʔτ͸ಉ͡ߦʹدͤΔ w ྫBQUHFUVQEBUFBQUHFUJOTUBMMFNBDT w

    #VJME,JUΛೖΕΔ w NPVOUUZQFDBDIFͷ׆༻
  28. %PDLFSpMFͷฒྻੑ w NVMUJTUBHFCVJMEΛ׆༻͢Δ w #VJME,JUΛೖΕΔ

  29. ϕʔεΠϝʔδͷ࢓૊ΈΛ஌Δ w %PDLFSΠϝʔδͷ࣮ମ͸6'4ͱݺ͹ΕΔ-BZFSFE'JMFTZTUFN w ڞ௨ͷϕʔεΠϝʔδΛ֤ΞϓϦέʔγϣϯͰ࢖͏ w τʔλϧͷϕʔεΠϝʔδʹ࢖͏σΟεΫ༰ྔ͕࡟ݮͰ͖Δ w 1VMM΍#VJMEʹ͔͔Δ͕࣌ؒ࡟ݮͰ͖Δ w

    ڞ௨ॲཧ͸ΠϝʔδԽ͢Δͷ΋ͭͷख
  30. ݁࿦#VJME,JUΛ࢖͏

  31. %PDLFSCVJMEͷ͓೰ΈϙΠϯτ w ΠϝʔδαΠζ w Ϗϧυͷ଎͞ w Մಡੑͱϝϯςφϯεੑˡ w ࠶ݱੑ w

    ηΩϡϦςΟ
  32. Ϗϧυͷ଎౓ͱΠϝʔδͷαΠζ Λ࠷༏ઌ͍ͯ͘͠ͱɺ࣍ୈʹ %PDLFSpMF͕ຐ۸ͱԽ͢

  33. ຊηΫγϣϯͰ͸ɺ%PDLFSpMFͷ ՄಡੑɾϝϯςφϯεੑΛͲ͏ߴ Ί͍͔ͯ͘ʹ͍ͭͯߟ͑ͯΈΔ

  34. %PDLFSpMFͷՄಡੑ w ಡΈ΍͍͢%PDLFSpMFͱ͸Կ͔ w ΍͍ͬͯΔ͜ͱ͕໌֬ w ߦ਺͕୹͍ w %PDLFSʹ͓͚ΔίϯςφϓϩηεͷݪଇΛकΔ w

    FOUSZQPJOUTIʹཔΓ͗ͯ͢Δ৔߹ઃܭ͕Α͘ͳ͍͔΋͠Εͳ͍ w ֤εςʔδͷ໋໊نଇ΋ॏཁ w ίϝϯτͰ͸8IBUͰ͸ͳ͘)PX8IZΛॏࢹ͢Δ
  35. %PDLFSpMFͷϝϯςφϯεੑ w όʔδϣϯͷ໌هͳͲ͕ඞཁͳύοέʔδΛೖΕΔ৔߹͸ ม਺ʹ੾Γग़͢ w มߋ؅ཧͷखؒΛݮΒ͢ w Ϗϧυͷͨͼʹ݁Ռ͕มΘΔͷ͸࿦֎ w λά΋ͦ͏͕ͩɺͰ͖ΔݶΓඞཁͳπʔϧͷόʔδϣϯ͸

    ݻఆ͓ͯ͘͠
  36. %PDLFSCVJMEͷ͓೰ΈϙΠϯτ w ΠϝʔδαΠζ w Ϗϧυͷ଎͞ w Մಡੑͱϝϯςφϯεੑ w ࠶ݱੑˡ w

    ηΩϡϦςΟ
  37. %PDLFSpMFͷ࠶ݱੑ w ϝϯςφϯεੑͷͱ͜ΖͰݴٴͯͨ͠ͷͰεΩοϓ

  38. %PDLFSCVJMEͷ͓೰ΈϙΠϯτ w ΠϝʔδαΠζ w Ϗϧυͷ଎͞ w Մಡੑͱϝϯςφϯεੑ w ࠶ݱੑ w

    ηΩϡϦςΟˡ
  39. %PDLFSpMFʹ͓͚ΔηΩϡϦςΟ w ػີ৘ใͷऔѻ͍ w Ϗϧυதʹ(JUQVMM΍44)͢Δͱ͖ͷ伴ͷ؅ཧ w ΞϓϦέʔγϣϯͷγʔΫϨοτΩʔͷ؅ཧ w Ұ࣌తͳσʔλΛͲ͜ʹͲ͏อଘ͢Δ͔ͷઃܭ

  40. 44)΍(JUͷ伴

  41. NPVOUUZQFTFDSFU Λ࢖͏

  42. NPVOUUZQFTFDSFUͱ͸ w %PDLFS͔Βೖͬͨ৽໋͍͠ྩ w %PDLFSϏϧυதʹػີ৘ใΛ҆શʹϚ΢ϯτ͢ΔͨΊͷػ ೳ w ੒Ռ෺ʹ伴͕࢒Βͳ͍ʂ΂ΜΓʂ w 36/NPVOUUZQFTFDSFU

    JETTI UBSHFUSPPUTTI JE@STBHJUDMPOF
 ˢΈ͍ͨͳײ͡ͰࢦఆͰ͖Δɻ
  43. ΋͏ͪΐͬͱଓ͖·͢

  44. %PDLFSpMFͷઓུͱ %PDLFSΒ͍͠ΞϓϦέʔγϣϯͷ ࡞ΓํͱͷؔΘΓํ

  45. %PDLFSΒ͍͠ΞϓϦέʔγϣϯʁ w %PDLFSͷྑ͞ w มԽͷ଎͍ΞϓϦέʔγϣϯʹରͯ͠ɺ#VJME4IJQ3VO ͷΤίγεςϜΛఏڙ͍ͯ͠Δ͜ͱ w ਖ਼͘͠࢖͑͹ʮͲ͜Ͱ΋ʯʮಉ͡Α͏ʹʯಈ͘؀ڥ͕࣮ ݱͰ͖Δ

  46. %PDLFSΛlਖ਼͘͠z࢖͏ w ෆཁͳ΋ͷ͸ೖΕͳ͍ w มߋͷೖΓ΍͍͢Օॴ͸΂ͨॻ͖ʹ͠ͳ͍ w ։ൃ؀ڥɺݕূ؀ڥɺຊ൪؀ڥͰͰ͖ΔݶΓಉ͡ΠϝʔδΛ࢖͏ w ؀ڥ͝ͱͷґଘੑ஫ೖʹ͸؀ڥม਺΍FOUSZQPJOUΛ׆༻͢Δ w

    ίϯςφϓϩηεͷݪଇΛ஌Δ कΔ͔Ͳ͏͔͸ผͱͯ͠
  47. ͱ͸͍͑ӡ༻࣌ʹࠔΔ͜ͱ΋͋Δ w Ͳ͏ͯ͠΋44)͍ͨ͠ɾɾɾWJN࢖͍͍ͨɾɾɾ w 44)͸جຊ࢖Θͳ͍ 'BSHBUFͱ͔Ͱແ͍ݶΓɺFYFDJUͱ͔͢ Ε͹໰୊ͳ͍͸ͣ  w σόοάπʔϧ͕ೖ͍ͬͯͳ͍ίϯςφ಺ͰσόοάπʔϧΛ

    ىಈ͢Δํ๏ 1*%ωʔϜεϖʔεͷڞ༗ػೳΛ࢖͏  w EPDLFSSVOSNJUQJEDPOUBJOFSBQQ EFCVH@JNBHFUBHTI
  48. ΍΂͑ɺSVOͪ͠Όͬͨ

  49. ։ൃͱӡ༻ͱΞϓϦͷߏ଄ͷ౎߹ w ͜͜͸Ͳ͏ͯ͠΋ίϯύΠϧ͠௚͕͠ඞཁͳͷͰ4UBHJOH ͱ1SPEVDUJPOͰΠϝʔδΛ෼͚ͳ͍ͱ͍͚ͳ͍ΜͰ͢ʂ w ΞϓϦέʔγϣϯͷ࣮ߦʹΫιͰ͔͍όΠφϦ͕ඞཁͰϏ ϧυ͢Δͷʹࢮ͵΄Ͳ͕͔͔࣌ؒͬͯ։ൃͲ͜Ζ͡Όͳ͍ ΜͰ͢ʼʻ w ΠϝʔδαΠζখ͘͞͠Α͏ͱ͢ΔͱΩϟογϡ͕ޮ͖ͮ

    Β͘ͳͬͯਏ͍ΜͰ͕͢ʁʁʁ
  50. ͍Ζ͍Ζ͋ΔΑͶ

  51. ϕετϓϥΫςΟεͱ%PDLFSXBZ ͷཱ྆ΛɺΞϓϦέʔγϣϯͷߏ଄ ΛकΓͳ͕Β୲อ͢Δͷ͸೉͍͠ɻ

  52. ϕετϓϥΫςΟε͸ ͋͘·Ͱ΋ϕετϓϥΫςΟε

  53. େࣄͳͷ͸͖ͪΜͱ஌্ͬͨ Ͱɺ༻๏༻ྔΛकͬͯ࢖͏͜ͱ

  54. ,OPXZPVSUPPMT  LOPXZPVSBQQMJDBUJPO

  55. 5IBOLTGPSZPVSBUUFOUJPO