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

試行錯誤のための Docker 活用術

試行錯誤のための Docker 活用術

PyCon Kyushu in Okinawa 2019

Yuki Ishikawa

May 18, 2019
Tweet

More Decks by Yuki Ishikawa

Other Decks in Technology

Transcript

  1. ࿩͢͜ͱ  %PDLFSͱ͸ͳʹ͔ NJO   %PDLFSಋೖʹΑͬͯಘΒΕΔ΋ͷ NJO  

    %PDLFSಋೖͷצॴ NJO   %PDLFSςΫχοΫ̐બ NJO   σϞ ͕࣌ؒ༨Ε͹
  2. %PDLFS w ίϯςφܕͷԾ૝Խπʔϧ w ϗετ04ͱΧʔωϧΛڞ༗͢Δ w -JOVYͰ͔͠ಈ͔ͳ͍ ˞  w

    ىಈ͕ര଎ ˞%PDLFS%FTLUPQ NBD04 8JOEPXT Ͱ͸ɺ-JOVY7.Λ
 ɹ࡞ͬͯͦͷ্Ͱ%PDLFS&OHJOFΛಈ͔͍ͯ͠Δ ϋʔυ΢ΣΞ 04Χʔωϧ %PDLFSΤϯδϯ ίϯςφϓϩηε ίϯςφϓϩηε ϋʔυ΢ΣΞ ϋΠύʔόΠβ 04Χʔωϧ ϓϩηε ϓϩηε 04Χʔωϧ ϋΠύʔόΠβܕ ίϯςφܕ
  3. ίϯςφΛىಈ͢ΔࡍͷΦϓγϣϯ w ؀ڥม਺Λઃఆ w ϘϦϡʔϜΛϚ΢ϯτ w ϙʔτΛׂΓ౰ͯ FUD ίϯςφ Πϝʔδ

    EPDLFSSVOJUa F%"5"#"4&@63-NZTRMa W QXE BQQa Qa NZBQQJNBHFa QZUIPOBQQQZ
  4. "ʮ%PDLFS͸+BWBͱಉ͡ʯ ʮ࣮ߦՄೳͳΧλϚϦ ΞϓϦέʔγϣϯ Λ࡞Δʯͱ͍͏఺Ͱಉ͡ +BWB %PDLFS +BWBͷίʔυΛॻ͘ %PDLFSpMFΛॻ͘ ίϯύΠϧ͢Δ KBSϑΝΠϧ͕Ͱ͖Δ

    Ϗϧυ͢Δ Πϝʔδ͕Ͱ͖Δ +BWBϥϯλΠϜ +3& Ͱ࣮ߦ͢Δ
 ϓϩηε͕ಈ͘ ίϯςφϥϯλΠϜͰ࣮ߦ͢Δ
 ίϯςφ͕ಈ͘
  5. ʮ؀ڥͷ࠶ݱੑʯ͕͋Δ͜ͱͷྑ͞ w ϩʔϧόοΫ͕༰қ w յΕͨΒίϯςφΛফͯ͠࡞Γ௚ͤ͹ྑ͍ w ؾ݉Ͷͳ͘؀ڥΛյͤΔɺνϟϨϯδ͠΍͍͢ w ϙʔλϒϧ w

    %PDLFSpMF΋͘͠͸ΠϝʔδΛڞ༗͢Δ͚ͩͰಉ͡؀ڥ͕࡞ΕΔ w νʔϜϝΠτ΍ސ٬ͷ؀ڥͰಉ͡΋ͷΛ͙͢ʹಈ͔ͤΔ w ؀ڥͦͷ΋ͷΛόʔδϣϯ؅ཧԼʹஔ͚Δ w %PDLFSpMFΛόʔδϣϯ؅ཧ͢Ε͹ͦΕ͕ʮ؀ڥߏஙͷखॱॻʯʹͳΔ
  6. "OBDPOEB w σʔλ෼ੳ ػցֶशͰΑ͘࢖͏πʔϧ͕
 ·ͱΊͯೖ͍ͬͯΔσΟετϦϏϡʔγϣϯ w ʮ1ZUIPOͷϥΠϒϥϦूʯͰ͸ͳ͍ w "OBDPOEB͸ެࣜͷ%PDLFS*NBHF͕ެ։͞Ε͍ͯΔ EFCJBOϕʔε

     w IUUQTIVCEPDLFSDPNSDPOUJOVVNJPBOBDPOEB w "OBDPOEBΛϕʔεʹ෼ੳ؀ڥΛ࡞Δͱͱͯ΋ָ Ҿ༻ɿIUUQTXXXBOBDPOEBDPNEJTUSJCVUJPO
  7. 5IF;PNCJF3FBQJOH1SPCMFN %PDLFSʹ͸;PNCJF3FBQJOHͱݺ͹ΕΔ໰୊͕͋Δ Docker ͷ৔߹ɺಛʹߟྀͤͣϓϩηεΛ࣮ߦͤ͞ΔͱΤϯτϦʔϙΠϯτͱͯ͠ઃఆͨ͠ϓϩηε͕ PID 1 Ͱಈ࡞͠·͢ɻ Linux Ͱ͸ىಈ࣌ʹ࠷ॳʹىಈ͢Δ init

    ϓϩηεʹ PID 1 ׂ͕ΓৼΒΕɺPID 1 ͷϓϩηεʹ͍ͭͯ͸ಛघͳߟྀ͕͞Εɺ σϑΥϧτͰγάφϧΛແࢹ͢Δઃఆͱͳ͍ͬͯΔΑ͏Ͱ͢ɻ ͦͷͨΊɺ docker stop ίϚϯυͳͲͰ SIGTERM γάφϧΛૹͬͯ΋ϓϩηε͕ఀࢭ͞ΕͣɺҰఆ࣌ؒޙʹλΠϜΞ΢τͯ͠ SIGKILL Ͱڧ੍ऴྃ͠·͢ɻ Ҿ༻ɿ%PDLFSͱJOJUͱίϯςφΦʔέετϨʔγϣϯͰͷઃఆʹ͍ͭͯEFGZBTVIBSV TFMG  IUUQZBTVIBSVIBUFOBCMPHDPNFOUSZ
  8. (16ͱ͸ w άϥϑΟοΫͷॲཧʹಛԽͨ͠ϓϩηοα w $16ͱൺֱͯ͠ ୯७ͳฒྻԋࢉΛߴ଎ʹߦ͏͜ͱ͕Ͱ͖ΔͨΊɺ
 ۙ೥Ͱ͸൚༻ܭࢉʹ΋࢖ΘΕΔ͜ͱ͕ଟ͘ͳ͖ͬͯͨ (1(16  w

    ಛʹ/7*%*"ࣾͷ(16Ͱ͸$6%" DV%//ͱ͍ͬͨϥΠϒϥϦ͕
 ެ։͞Ε͓ͯΓɺσΟʔϓϥʔχϯάͷܭࢉʹར༻͞ΕΔ͜ͱ͕ଟ͍ w Ҏ߱ͷεϥΠυͰ͸ɺ(16ͱ͍͏ϫʔυ͸ಛʹ໌ࣔ͞Εͯ
 ͍ͳ͍ݶΓ/7*%*"ࣾͷ(16Λࢦ͢ɺͱ͍͏͜ͱʹ͢Δ
  9. /7*%*"%PDLFS w ௨ৗɺ%PDLFSίϯςφ಺͔Β͸
 (16ʹΞΫηεͰ͖ͳ͍
 /7*%*"υϥΠό͕ར༻Ͱ͖ͳ͍  w /7*%*"͕ࣾެ։͍ͯ͠Δ
 /7*%*"%PDLFSΛ࢖͏͜ͱͰ
 ίϯςφ಺͔ΒͰ΋υϥΠό͕


    ར༻Ͱ͖ΔΑ͏ʹͳΔ w /7*%*"%PDLFSΛ࢖͓͏ Ҿ༻ɿ&OBCMJOH(16TJOUIF$POUBJOFS3VOUJNF&DPTZTUFNc/7*%*"%FWFMPQFS#MPH IUUQTEFWCMPHTOWJEJBDPNHQVDPOUBJOFSTSVOUJNF
  10. 98JOEPX4ZTUFN 9 w (6*Λѻ͏ͨΊͷϓϩτίϧ w ΫϥΠΞϯταʔόϞσϧ w σΟεϓϨΠͳͲͷσόΠεଆ͕αʔό w (6*ΞϓϦέʔγϣϯଆ͕ΫϥΠΞϯτ

    w αʔόΫϥΠΞϯτؒͷ௨৴͸ҟͳΔϚγϯؒͰ͋ͬͯ΋ಈ࡞͢Δ w ҟͳΔΞʔΩςΫνϟɾҟͳΔ04ؒͰ͋ͬͯ΋໰୊ͳ͍
  11. %PDLFS ղܾࡦ 9ΞϓϦ σΟεϓϨΠ  9αʔό 9ΫϥΠΞϯτ σΟεϓϨΠMPDBMIPTU͕ ݟ͔ͭͬͨʂʂʂ ΢Οϯυ΢͕

    ඳը͞ΕΔ UNQ9VOJY 9αʔό͕-JTUFO͍ͯ͠Δ ιέοτΛίϯςφʹϚ΢ϯτ͢Δ ˞ 9αʔόʹ઀ଓ͢ΔͨΊͷೝূ৘ใ d9BVUIPSJUZ ΋ίϯςφଆʹڞ༗͢Δඞཁ͕͋Δ ˞ ιέοτΛϚ΢ϯτͤͣͱ΋ɺϗετ04ͷ9αʔόʹ௚઀ΞΫηεͰ͖ΔͳΒͦΕͰ΋͍͍
  12. ·ͱΊ  w %PDLFS͸+BWB ޠฐ  w ʮίϯςφ͸ϓϩηεʯ w %PDLFSಋೖʹΑͬͯʮ؀ڥͷ࠶ݱੑʯ͕ಘΒΕΔ

    w ϩʔϧόοΫ͕༰қ ϙʔλϒϧ ؀ڥΛόʔδϣϯ؅ཧͰ͖Δ
 ͳͲͷϝϦοτ͕͋Δ w %PDLFSΛ͏·͘ѻ͏ʹ͸ίπ͕͍Δ w ίϯςφΛεςʔτϨεʹอͭ ͜·ΊʹߏஙखॱΛηʔϒ͢Δ