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

Dockerはじめの一歩 / The first step of Docker

ihcomega56
April 22, 2021

Dockerはじめの一歩 / The first step of Docker

JFrog webinar

ihcomega56

April 22, 2021
Tweet

More Decks by ihcomega56

Other Decks in Technology

Transcript

  1.  ʮ͸͡ΊͷҰาʯγϦʔζ ಛ௃ • ಛఆͷٕज़ʹ͍ͭͯɺΠϥετ΍ྫ͑Λ࢖ͬͯઆ໌͠·͢ • ෺ࣄΛֶͿ࣌͸֓ཁ΍શମ૾Λ஌͔ͬͯΒਂງΓ͍ͨ͠೿ɺ Ͱ΋ࣗྗͰ࢝ΊΔͷ͕ۤख ࠳ંͪ͠Ό͏ ೿ʹΦεεϝͰ͢

    • ͱʹ͔ࣗ͘Β৮ͬͯಈ͔ͯ͠Έ͍ͨ೿ʹ͸෺଍Γͳ͍͔΋ʜ աڈ࡞ • ,VCFSOFUFT͸͡ΊͷҰา IUUQTTQFBLFSEFDLDPNJIDPNFHBUIFGJSTUTUFQPGLVCFSOFUFT • (JU (JU)VC(JU)VC"DUJPOT͸͡ΊͷҰา IUUQTTQFBLFSEFDLDPNJIDPNFHBUIFGJSTUTUFQPGHJUHJUIVCBOEHJUIVCBDUJPOT
  2.  %PDLFSͷͳ͍։ൃ؀ڥߏங ؀ڥߏங खॱͰ͢ ઃ ఆ ϑ Ν Π ϧ

    Λ ॻ ͖ ׵ ͑ Δ ݴ ޠ ͷ ։ ൃ Ω ο τ Λ Π ϯ ε τ ʔ ϧ ͢ Δ σ ʔ λ ϕ ʔ ε Λ Π ϯ ε τ ʔ ϧ ͢ Δ σ ʔ λ ϕ ʔ ε ͷ ς ʔ ϒ ϧ ΍ Ϣ ʔ β ʔ Λ ༻ ҙ ͢ Δ σ ʔ λ Λ ొ ࿥ ͢ Δ *%&΍ ς Ω ε τ Τ σ Ο λ Λ Π ϯ ε τ ʔ ϧ ͢ Δ ͦ ͷ ଞ ඞ ཁ ͳ ϛ υ ϧ ΢ Σ Ξ Λ ༻ ҙ ͢ Δ
  3.  %PDLFSͷͳ͍։ൃ؀ڥߏங Τϥʔ͕ ग़ͨ खॱॻ͕ ݹ͍ ྡͷਓͱ Կ͔ҧ͏ όʔδϣϯ ҧͬͨ

    ઃ ఆ ϑ Ν Π ϧ Λ ॻ ͖ ׵ ͑ Δ ݴ ޠ ͷ ։ ൃ Ω ο τ Λ Π ϯ ε τ ʔ ϧ ͢ Δ σ ʔ λ ϕ ʔ ε Λ Π ϯ ε τ ʔ ϧ ͢ Δ σ ʔ λ ϕ ʔ ε ͷ ς ʔ ϒ ϧ ΍ Ϣ ʔ β ʔ Λ ༻ ҙ ͢ Δ σ ʔ λ Λ ొ ࿥ ͢ Δ *%&΍ ς Ω ε τ Τ σ Ο λ Λ Π ϯ ε τ ʔ ϧ ͢ Δ ͦ ͷ ଞ ඞ ཁ ͳ ϛ υ ϧ ΢ Σ Ξ Λ ༻ ҙ ͢ Δ
  4.  %PDLFSͷͳ͍։ൃ؀ڥߏங %PDLFS্Ͱಈ͔͢νϟϯεʂ ઃ ఆ ϑ Ν Π ϧ Λ

    ॻ ͖ ׵ ͑ Δ ݴ ޠ ͷ ։ ൃ Ω ο τ Λ Π ϯ ε τ ʔ ϧ ͢ Δ σ ʔ λ ϕ ʔ ε Λ Π ϯ ε τ ʔ ϧ ͢ Δ σ ʔ λ ϕ ʔ ε ͷ ς ʔ ϒ ϧ ΍ Ϣ ʔ β ʔ Λ ༻ ҙ ͢ Δ σ ʔ λ Λ ొ ࿥ ͢ Δ *%&΍ ς Ω ε τ Τ σ Ο λ Λ Π ϯ ε τ ʔ ϧ ͢ Δ ͦ ͷ ଞ ඞ ཁ ͳ ϛ υ ϧ ΢ Σ Ξ Λ ༻ ҙ ͢ Δ
  5.  %PDLFSͷ͋Δ։ൃ؀ڥߏங %PDLFSΛ Π ϯ ε τ ʔ ϧ ͢

    Δ %PDLFSΠ ϝ ʔ δ Λ औ ಘ ͢ Δ ͜͏ͳΔ͔΋ ઃ ఆ ϑ Ν Π ϧ Λ ॻ ͖ ׵ ͑ Δ ݴ ޠ ͷ ։ ൃ Ω ο τ Λ Π ϯ ε τ ʔ ϧ ͢ Δ *%&΍ ς Ω ε τ Τ σ Ο λ Λ Π ϯ ε τ ʔ ϧ ͢ Δ
  6.  Ծ૝Ϛγϯͷ୆಄ • Ծ૝Խιϑτ΢ΣΞΛ༻͍ͯɺ୆ͷαʔόʔʹෳ਺ͷԾ૝త ͳαʔόʔ Ծ૝Ϛγϯ Λߏங͢Δ • Ծ૝Ϛγϯຖʹ؀ڥ 04ɺϛυϧ΢ΣΞɺΞϓϦέʔγϣϯ

    ͕෼཭Ͱ͖ɺ෺ཧϚγϯ୆ʹΑΔӡ༻ΑΓϝϦοτ͕େ͖͍ ͨΊਁಁͨ͠ • 04ͷΠϯετʔϧ΍ىಈ͕ඞཁͳ෼ɺϋʔυ΢ΣΞϦιʔε ΍࣌ؒΛ ൺֱత ଟ͘ཁ͢Δ Θͨ͠͸ ୆ ιϑτ΢ΣΞͷྗ ·ΔͰ ୆ʂ ྫ αʔόʔͷ Ծ૝Խ
  7. • ίϯςφͰ࣮ݱ͍ͯ͠Δͷ΋Ծ૝ԽͷҰछͰ͋Δ • αʔόʔΛԾ૝Խ͢Δͱϋʔυ΢ΣΞ͕ෳ਺͋Δ͔ͷΑ͏ʹ ݟ͑ΔͷͰɺ͜ΕΛʮϋʔυ΢ΣΞϨϕϧͷԾ૝ԽʯͱݺͿ • ίϯςφ͸ಉҰ04্ͰԾ૝ԽΛ࣮ݱ͢Δʮ04ϨϕϧͷԾ૝ Խʯʹ͋ͨΔ  ίϯςφʹΑΔԾ૝Խ

    ϗετ04 ίϯςφΤϯδϯ ίϯςφ ΞϓϦ ΞϓϦ ΞϓϦ ίϯςφ ΞϓϦ ΞϓϦ ϋΠύʔόΠβʔ 7. ΞϓϦ ΞϓϦ ΞϓϦ 7. ΞϓϦ ΞϓϦ ήετ04 ήετ04 ·ΔͰ ผʑͷ αʔόʔʂ ·ΔͰ ผʑͷ 04ʂ ϋʔυ΢ΣΞ Ϩϕϧͷ Ծ૝Խ 04Ϩϕϧͷ Ծ૝Խ αʔόʔ αʔόʔ ˞ॴҦʮϋΠύʔόΠβʔܕʯͷਤɻ04ͱઐ༻ιϑτΛ࢖͏ʮϗετܕʯ΋͋Δ
  8. • ϋʔυ΢ΣΞελοΫ΍04 ͷϑϧػೳ Λؚ·ͣɺΞϓϦ έʔγϣϯͱґଘؔ܎ͷΈΛύοέʔδԽ͢ΔͨΊ • ىಈ͕࣌ؒ୹͍ • ύοέʔδͷαΠζ͕খ͍͞ •

    ࢖༻͢Δϋʔυ΢ΣΞϦιʔε͕খ͍͞ ˠࡢࠓͷιϑτ΢ΣΞ։ൃͷτϨϯυͱϚον͢Δ • Ϋϥ΢υ • %FW0QT • $*$% • ϚΠΫϩαʔϏε ͳͲ  ίϯςφʹΑΔԾ૝ԽͷϝϦοτ TUV<
  9. • ίϯςφΛ࡞੒͢ΔͨΊͷ໋ྩ͕ೖͬͨύοέʔδ • طʹଘࡏ͢Δ΋ͷΛ࢖͏͜ͱ΋ɺ࡞Δ͜ͱ΋Ͱ͖Δ • Πϝʔδ͕࣮ߦঢ়ଶʹͳͬͨΠϯελϯε͕ίϯςφ  %PDLFSΠϝʔδ %PDLFS Πϝʔδ

    ࣮ߦ؀ڥͱͯ͠"MQJOF ܰྔͷ-JOVY Λ࢖ͬͯʂ +BWBͱ(SBEMFΛΠϯετʔϧͯ͠ʂ ࣮ߦϑΝΠϧ͸͜ͷσΟϨΫτϦʹ഑ஔͯ͠ʂ +BWBΞϓϦέʔγϣϯΛ࣮ߦͯ͠ʂ
  10.  ஫͜ͷࢿྉͰͷ%PDLFSίϚϯυͷѻ͍ํ • ͜ΕҎ߱ɺઆ໌ʹؔ࿈͢ΔίϚϯυΛ্هϑΥʔϚοτͰεϥΠυʹهࡌ ͠·͢ • ίϚϯυͷ໊લΛ঺հ͢ΔʹͱͲΊɺҾ਺΍ΦϓγϣϯͳͲΛৄ͘͠આ໌ ͢Δ͜ͱ͸ ΄ͱΜͲ ͠·ͤΜ

    • ࠓ೔͸ΠϝʔδΛ௫Ή͜ͱ͕໨తͰ͋ΔͨΊ • ίϚϯυͷ۩ମతͳ࢖͍ํ͸खΛಈ͔͞ͳ͍ͱ਎ʹ͔ͭͳ͍ͱߟ͑ΔͨΊ ίϯςφΛ࡞੒ɾ࣮ߦ͢Δ docker run
  11. ϥΠϒϥϦͷ%PDLFSΠϝʔδΛ࢖͏ • %PDLFS্Ͱಈ͘ΞϓϦέʔγϣϯͷ Πϝʔδ͕ͨ͘͞Μެ։͞Ε͍ͯΔ • ࠷΋Ұൠతͳެ։ઌ͕ʮ%PDLFS)VCʯͱ͍͏ϨδετϦ  طʹ͋Δ%PDLFSΠϝʔδΛ࢖͏ᶃ s+*t%&uvwxyY Az9{1|}~6

    •€•‚GYƒ„… †•€‡ˆ{C‡P ‰‚GŠ ίϯςφΛ࡞੒ɾ࣮ߦ͢Δ docker run σϑΥϧτ͸ϑΥΞάϥ΢ϯυ ࣮ߦɻόοΫάϥ΢ϯυʹ͢Δ ʹ͸EΦϓγϣϯΛ͚ͭΔ
  12.  Α͘࢖͏ίϯςφͷૢ࡞ ίϯςφΛҰཡදࣔ͢Δ docker ps ࣮ߦ த ఀࢭ த ίϯςφΛఀࢭ͢Δ

    docker stop ίϯςφΛىಈ͢Δ docker start ࣮ߦதͷίϯςφ಺ͰίϚϯυΛ࣮ߦ͢Δ docker exec ίϯ ςφ ࣮ߦதͷίϯςφ಺ͷϩάΛग़ྗ͢Δ docker logs ίϯςφΛ࡟আ͢Δ docker rm ର৅͸ఀࢭதͷίϯςφɻ ಈ͍͍ͯΔ΋ͷΛࢭΊΔ࣌͸ GΦϓγϣϯΛ͚ͭΔ ͪΐͬͱ͓ͨ͠ࢼ͠΍ ௐࠪʹ࢖͏͜ͱ͕ଟ͍ ର৅͸࣮ߦதͷίϯςφɻ ࢭ·͍ͬͯΔ΋ͷ΋ݟΔ࣌͸ BΦϓγϣϯΛ͚ͭΔ ίϯςφ͔ΒΠϝʔδΛੜ੒͢Δ docker commit ೖ໳ॻ αΠτ ͰΑ͘࢖͏ͱ ॻ͔Ε͍ͯͨΓ͢Δ͕ɺ ͋·Γ࢖Θͳ͍ײ֮ʜ
  13. • FROM ϕʔεͱͳΔΠϝʔδΛࢦఆ͢Δ • RUN Ϗϧυ࣌ʹίϯςφ಺ͰίϚϯυΛ࣮ߦ͢Δ • ENV ,FZ7BMVFܗࣜͰ؀ڥม਺Λࢦఆ͢Δ •

    ADD, COPY Πϝʔδ಺΁ϑΝΠϧΛίϐʔ͢Δ • CMD, ENTRYPOINT ίϯςφىಈ࣌ʹ࣮ߦ͢ΔίϚϯυ΍Ҿ਺Λ ͋ ࢦఆ͢Δ  جຊతͳ%PDLFSGJMFͷίϚϯυ s+*t%&6˜™G =ešB›@ƒ œ•ž™q1 Ÿ 6Š¡¢3r
  14. • LABEL • EXPOSE • VOLUME • USER • WORKDIR

    • ARG • ONBUILD • STOPSIGNAL • HEALTHCHECK • SHELL  ͦͷଞͷ%PDLFSGJMFͷίϚϯυ £¤5¥¦^ §¨EdEbr
  15. • ʮԿΛ࢖ͬͯͲΜͳ͜ͱΛͲΜͳ෩ʹ࣮ݱ͍͔ͨ͠ʯ͕໌֬ʹ ͳ͍ͬͯΕ͹ɺௐ΂ͳ͕Βهड़͍͚ͯ͠͹େৎ෉ʂ • จ๏͕ޡ͍ͬͯͨΒϏϧυ࣌ʹΤϥʔʹͳΔ͠ɺ࣮ߦͯ͠Έͯ ؒҧ͍ͬͯͨΒ௚ͤ͹ྑ͍ • %PDLFSͷίϚϯυ͕ࢦ͢΋ͷ͸৭ʑ͋ΔͷͰɺࣗ෼ͷதͰ෼ྨ ͯ͠ΈΔͱࠓԿ͍ͯ͠Δ͔෼͔Γ΍͍͢ •

    %PDLFSGJMF಺ʹॻ͘΋ͷ • ίϯςφΛૢ࡞͢Δ΋ͷ • ΠϝʔδΛૢ࡞͢Δ΋ͷ • ϦϙδτϦʹର͠ૢ࡞͢Δ΋ͷ  ίϚϯυͱฉ͘ͱ೉ͦ͠͏͚ͩͲ M©’ª«^P ¬-6®¯Gq“ C°A±B› U°9PE²™S ³´EFP zABYšµBƒ ¶i·‚’SY^ ¸¹
  16. • ઃఆͷશମ૾΋ৄࡉ΋໌֬Ͱ෼͔Γ΍͍͢ • όʔδϣϯ؅ཧͰ͖Δ ΋ͪΖΜόʔδϣϯͷߦ͖དྷ΍ڞಉฤू ͕͠΍͘͢ͳΔ • ಺༰ΛγΣΞ͠΍͍͢ • ಉ͡ઃఆΛ࠶ݱͰ͖Δ

    • ώϡʔϚϯΤϥʔ͕ى͜Γʹ͍͘ ʮ*OGSBTUSVDUVSFBT$PEFʯ  ͳͥઃఆΛϑΝΠϧʹॻ͖ى͜͢ͷ͔ º»5S35 ¼½•ˆ¾ˆ¾ ™GAz9{¿ À17ÁAD1 IJ’YK<
  17.  ;Γ͔͑Γ • %PDLFSͱ͸Կ͔ • ΞϓϦέʔγϣϯͱґଘؔ܎ΛύοέʔδԽ࣮ͯ͠ߦ͢Δʮίϯςφʯٕज़ͷͭ • ͳͥ%PDLFS͕ਓؾͳͷ͔ • ΞϓϦέʔγϣϯಉ࢜ͷׯব΍ΠϯϑϥͷԚછʹΑΔো֐ΛݮΒͤΔ

    • ઃఆΛϑΝΠϧ %PDLFSGJMF Ͱॻ͚ΔͷͰϝϯςφϯε͠΍͍͢ • ༷ʑͳ؀ڥͷ্Ͱಉ͡ΞϓϦέʔγϣϯΛ͙͢ʹߏஙͰ͖Δ • Ծ૝Խٕज़ͷதͰ͸ܰྔͰɺ͔ͭߴ଎ʹಈ࡞͢Δ ͜ΕΒʹೲಘ͠ɺ%PDLFSΛ࢖͍࢝ΊΔͨΊͷҰา͕౿Έग़ͤͯ ͍ͨΒࠓ೔͸0,ʂ ·ͩଞʹ΋ίϚϯυ΋ػೳ΋େྔʜগ֮ͣͭ͑͠Α͏