コンテナ開発入門 1回目/Introduction to Container Development 1

Fd09da0d9751bb7875ef4ff7e6201860?s=47 muttan
October 24, 2018

コンテナ開発入門 1回目/Introduction to Container Development 1

Fd09da0d9751bb7875ef4ff7e6201860?s=128

muttan

October 24, 2018
Tweet

Transcript

  1. ίϯςφ։ൃೖ໳ Keisuke Kamiya

  2. ΠϯτϩμΫγϣϯ • ࠓճ͔ΒԿճ͔ʹ෼͚ͯίϯςφͱͦͷपลٕज़, ίϯ ςφΛ࢖ͬͨ։ൃํ๏౳ʹֶ͍ͭͯͼ·͢ • ࢀߟॻ੶
 Docker/Kubernetes
 ࣮ફίϯςφ։ൃೖ໳,
 ٕज़ධ࿦ࣾ,

    3,380ԁʴtax Ҿ༻ݩɿhttps://gihyo.jp/book/2018/978-4-297-10033-9
  3. ΠϯτϩμΫγϣϯ • ໨ඪ
 DockerԿ΋Θ͔Βͳ͍…͔ΒDockerνϣοτϫΧϧ͙ Β͍·Ͱ੒௕͠Α͏ • औΓѻ͏಺༰ 1. ͳͥDockerΛ࢖͏ͷ͔ 2.

    DockerίϯςφΛ࢖ͬͨΞϓϦέʔγϣϯͷ։ൃ 3. σϓϩΠ΍ӡ༻ ࠓ೔ͷ಺༰͸ಋೖฤͰ͢
  4. ࠓճͷςʔϚ

  5. Chapter 1 Dockerͷجૅ

  6. ໨࣍ 1. Dockerͱ͸ 1.1.Dockerͷجૅ֓೦ 1.2.Dockerͷߟ͑ʹ৮ΕΔ 2. DockerΛར༻͢Δҙٛ 2.1.؀ڥࠩҟ͔Βͷ୤٫ 2.2.ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞

  7. ໨࣍ 1. Dockerͱ͸ 1.1.Dockerͷجૅ֓೦ 1.2.Dockerͷߟ͑ʹ৮ΕΔ 2. DockerΛར༻͢Δҙٛ 2.1.؀ڥࠩҟ͔Βͷ୤٫ 2.2.ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞

  8. Dockerͱ͸ • Docker
 ίϯςφܕԾ૝Խٕज़Λ࣮ݱ͢ΔͨΊͷৗறΞϓϦέʔ γϣϯͱ, ͦΕΛૢ࡞͢ΔCLI͔ΒͳΔϓϩμΫτ ‣ ࣮ߦ͞ΕΔίϯςφʢDockerίϯςφʣΛ഑෍͢Ε ͹, ৗʹಉ͡؀ڥΛ࠶ݱՄೳ

    → ͦ΋ͦ΋ίϯςφͬͯͳΜͩ ݱஈ֊Ͱ͸, ͱΓ͋͑ͣίϯςφ͸DockerʹΑͬͯ࡞੒ ͞ΕΔήετOSͱߟ͓͑ͯ͘ͱྑ͍
  9. Dockerͱ͸ • Dockerͷ͍͍ͱ͜Ζ 1. ैདྷͷԾ૝؀ڥߏஙΑΓ΋, ΑΓߴ଎/ܰྔͳ؀ڥΛ ؆୯ʹߏங͢Δ͜ͱ͕Ͱ͖Δ - ΞϓϦέʔγϣϯ։ൃ؀ڥΛྫʹղઆ 2.

    ϙʔλϏϦςΟੑ - ຊ൪؀ڥ΁ͷσϓϩΠʹ΋଱͑͏Δ 1ͭ1ͭݟ͍͖ͯ·͢
  10. Ϣʔεέʔε1 Ծ૝؀ڥͷߏங

  11. Ծ૝؀ڥͷߏங • DockerΛ࢖͏ͱศརͳϢʔεέʔεʢͦͷ1ʣ ‣ ܰྔͳԾ૝؀ڥͷߏங ‣ WebΞϓϦέʔγϣϯʹඞཁͳιϑτ΢ΣΞ(Apache ΍nginxͳͲ)ΛϩʔΧϧʹߏங͢Δํ๏Λߟ͑Δ ‣ (ํ๏1)

    VMηοτΞοϓ͔Βߦ͏ ‣ (ํ๏2) DockerΛ࢖͏
  12. Ծ૝؀ڥͷߏஙʢํ๏1ʣ • ຊ൪؀ڥͱಉ͡OSΛೖΕͨԾ૝؀ڥΛ༻ҙ͠, ύοέʔ δϚωʔδϟΛ࢖ͬͯιϑτ΢ΣΞΛಋೖʢैདྷ๏ʣ ‣ ͔ͭͯΑΓ, ύοέʔδϚωʔδϟͷ͓͔͛Ͱ؀ڥߏ ஙʹ͔͔Δ࣌ؒ͸େ෯ʹ୹ॖ͞Εͨ ‣

    ͜ΕΛࣗಈԽ͢Δ΋ͷʹVirtualBox + Vagrantͱ͍͏ ํ๏΋͋Δ͕, VMͷηοτΞοϓʹ͸ͦΕͳΓʹ࣌ؒ ͕͔͔Δ
  13. Ծ૝؀ڥͷߏஙʢํ๏2ʣ • DockerΛ࢖༻͢Δ ‣ OSͱ࣮ߦʹඞཁͳίϚϯυ౳Λهड़ͨ͠ϑΝΠϧ (Dockerfile)Λ༻ҙ͓͖ͯ͠, ίϚϯυΛ࣮ߦ - ϩʔΧϧ؀ڥʹDocker؀ڥ͑͞ηοτΞοϓ͞Ε ͍ͯΕ͹,

    ैདྷ๏ΑΓ΋ߴ଎ɾܰྔͳԾ૝؀ڥΛߏ ஙՄೳ
  14. Ծ૝؀ڥͷߏஙʢํ๏2ʣ • ͳͥDocker͕޲͍͍ͯΔͷ͔ʁ ‣ ίϯςφࣗମ͕ඇৗʹܰྔ - VMΑΓ΋Φʔόʔϔου͕গͳ͍ ‣ ىಈ/࡟আ͕ඇৗʹߴ଎ -

    ؀ڥͷ࡞੒/ഁյʹ͔͔Δ͕࣌ؒগͳ͍ͨΊ, ؀ڥ࠶ ݱ͕खܰͰςετΛߦ͍΍͍͢
  15. Ϣʔεέʔε2 ຊ൪؀ڥ΁ͷσϓϩΠ

  16. ຊ൪؀ڥ΁ͷσϓϩΠ • DockerΛ࢖͏ͱศརͳϢʔεέʔεʢͦͷ2ʣ ‣ ຊ൪؀ڥ΁ͷΞϓϦέʔγϣϯͷσϓϩΠ ‣ ͳͥDocker͕ຊ൪؀ڥ΁ͷσϓϩΠʹద͍ͯ͠Δ͔ʁ ‣ ϩʔΧϧͰ࣮ߦ͍ͯ͠Δίϯςφ͸, ผͷDocker؀ڥ

    ʹ͍࣋ͬͯͬͯ΋ಉ༷ʹಈ࡞͢Δ ‣ ؀ڥࠩҟΛDocker͕ٵऩ͍ͯ͠Δ ‣ ৄ͘͠͸ޙͰղઆ͠·͢
  17. ໨࣍ 1. Dockerͱ͸ 1.1.Dockerͷجૅ֓೦ 1.2.Dockerͷߟ͑ʹ৮ΕΔ 2. DockerΛར༻͢Δҙٛ 2.1.؀ڥࠩҟ͔Βͷ୤٫ 2.2.ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞

  18. ίϯςφܕԾ૝Խͱ͸

  19. Dockerͷجૅ֓೦ • Dockerͱ͸ʢ࠶ܝʣ
 ίϯςφܕԾ૝Խٕज़Λ࣮ݱ͢ΔͨΊͷৗறΞϓϦέʔ γϣϯͱ, ͦΕΛૢ࡞͢ΔCLI͔ΒͳΔϓϩμΫτ ‣ ࣮ߦ͞ΕΔίϯςφʢDockerίϯςφʣΛ഑෍͢Ε ͹, ৗʹಉ͡؀ڥΛ࠶ݱՄೳ

    → ͦ΋ͦ΋ίϯςφͬͯͳΜͩ ! ͦ΋ͦ΋Ծ૝ԽͬͯͳΜͩ ·ͣͳͥԾ૝Խ͢Δͷ͔͔Βߟ͑ͯΈ·͠ΐ͏
  20. Ծ૝Խٕज़ • ͦ΋ͦ΋ͳͥԾ૝Խٕज़Λಋೖ͢Δͷ͔ ‣ ίετύϑΥʔϚϯεͷ޲্ → Ϧιʔε࢖༻཰ͷ޲্ɾӡ༻ͷ୯७Խ ‣ ؀ڥͷִ཭ →

    ࣮ߦ͢Δ؀ڥΛִ཭͢Δ • ༷ʑͳཧ༝͕͋Δ͕, DockerΛϩʔΧϧͰ࢖͏৔߹, ࣗ ਎ͷ؀ڥΛԚͣ͞ʹ(ίϯςφ಺͚ͩͰดͨ͡)؀ڥͱ͠ ͯ࢖༻͢Δ͜ͱ͕ଟ͍
  21. Ծ૝Խٕज़ • Ծ૝؀ڥͷ෼ྨ ‣ ϋΠύʔόΠβܕ(XenͳͲ)
 ϋΠύʔόΠβͱݴΘΕΔιϑτ΢ΣΞΛ༻͍ͯ, ϚγϯશମΛԾ૝ Խ͢Δ(ڱٛ) ‣ ϗετOSܕ(VirtualBox,

    VMWareͳͲ)
 Ծ૝ԽΞϓϦέʔγϣϯΛϗετOS্ʹΠϯετʔϧ͠, ͦͷ্Ͱ ϋʔυ΢ΣΞͷಈ͖ΛγϛϡϨʔτ ‣ ίϯςφܕ(DockerͳͲ)
 ϗετOS্ʹίϯςφϥϯλΠϜ͕ଘࡏ͠, ͦͷ্Ͱίϯςφ͕Ք ಇ. ϗετOSͱΧʔωϧΛڞ༗͍ͯ͠Δ
  22. Ծ૝Խٕज़ ௨ৗͷγεςϜ ϋΠύʔόΠβܕ ϗετOSܕ ίϯςφܕ(Docker) ϗετ04 8JOEPXTͳͲ "QQ "QQ "QQ

    ϗετ04 8JOEPXTͳͲ "QQ "QQ "QQ Ծ૝Խιϑτ ήετ04 ήετ04 ϋΠύʔόΠβ "QQ ήετ04 "QQ ήετ04 "QQ ήετ04 ϗετ04 8JOEPXTͳͲ ίϯςφ ίϯςφ "QQ %PDLFS ɿԾ૝ԽྖҬ
  23. ίϯςφܕԾ૝Խ • ίϯςφܕԾ૝Խ ‣ OSϨϕϧԾ૝Խ(Operating-system-level virtualization)ͱ΋ݺ͹ΕΔ ‣ ίϯςφܕԾ૝Խ͸, Ծ૝Խιϑτ΢ΣΞͳ͠ʹOSͷ ϦιʔεΛִ཭͠,

    Ծ૝తͳOS(ίϯςφ)Λ࡞Γग़͢ - ίϯςφΛ࡞Γग़͢Φʔόʔϔου͸, ଞͷԾ૝Խ ιϑτ΢ΣΞʹൺ΂Δͱগͳ͍
  24. ίϯςφܕԾ૝Խ • ίϯςφܕԾ૝Խ͸Ҏલ͔Βଘࡏ ‣ LXC(Linux Containers) - Dockerొ৔લ͔Βଘࡏ͍ͯ͠Δ - ϦιʔεΛִ཭͠,

    ίϯςφΛ૸ΒͤΔ • Docker΋͔ͭͯ͸LXCΛ࢖༻͍ͯͨ͠ ‣ ݱࡏ͸runCͱ͍͏ϥϯλΠϜΛ࢖༻͠Ծ૝ԽΛ࣮ݱ
  25. ίϯςφܕԾ૝Խ LXC ϗετ04 8JOEPXTͳͲ -9$ Docker ϗετ04 8JOEPXTͳͲ %PDLFS LFSOFM

    ίϯςφ ίϯςφ ίϯςφ ίϯςφ ίϯςφ ίϯςφ LFSOFM SVO$ • DockerͷίϯςφܕԾ૝Խٕज़ͷਪҠ ‣ ͔ͭͯ͸LXCܦ༝ͰίϯςφΛ࣮ߦ ‣ ݱࡏ͸, cgourps, namespace౳Λ௚઀ୟ͘libcontainer ܦ༝Ͱ࣮ߦ
  26. ΞϓϦέʔγϣϯʹϑΥʔΧεͨ͠Docker

  27. ΞϓϦέʔγϣϯʹϑΥʔΧε • LXC͸ϗετܕԾ૝ԽΑΓ΋ύϑΥʔϚϯεͰ༗ར • ҰํͰ, ෳ੡ͨ͠ΞϓϦέʔγϣϯΛผͷLXC͕Մಈ͠ ͍ͯΔϗετͰ࣮ߦ͢Δͱ͖ʹ, ૝ఆͱҟͳΔಈ࡞Λ͢ Δ͜ͱ͕͋Δ ‣

    LXCϗετͷઃఆͷࠩҟ͕ݪҼ ‣ σϓϩΠͨ͠ΞϓϦέʔγϣϯ͕ϩʔΧϧͱຊ൪؀ ڥͰҟͳΔ͜ͱʹ
  28. ΞϓϦέʔγϣϯʹϑΥʔΧε • Docker͸ΞϓϦέʔγϣϯͷσϓϩΠΛத৺ʹߟ͑Δ ‣ ҎԼͷΑ͏ͳಛ௃͕͋Δ - ϗετʹࠨӈ͞Εͳ͍࣮ߦ؀ڥ - ίʔυʹΑΔίϯςφߏ੒ͷ؅ཧ -

    Πϝʔδͷόʔδϣϯ؅ཧ - DockerϨδετϦ - ϨΠϠʔʹΑΔΠϝʔδͷอଘ
  29. ΞϓϦέʔγϣϯʹϑΥʔΧε • DockerͰ͸, ΞϓϦέʔγϣϯΛίʔυͰ؅ཧ͢Δ ‣ DSL(Dockerfile)ʹΑΔ؅ཧ - ίʔυͰߏ੒Λ؅ཧͰ͖Δ(Infrastructure as code)

    - ߏ੒Λόʔδϣϯ؅ཧ͢Δ͜ͱ͕Ͱ͖Δ • ΞϓϦέʔγϣϯ͚ͩͰͳ͘, ࣮ߦ؀ڥ(os)΋ಉ࣌ʹσ ϓϩΠ ‣ ࣮ߦ؀ڥ͝ͱ഑෍͢Δ͜ͱͰґଘؔ܎Λղফ DSL : domain-specific language
  30. ໨࣍ 1. Dockerͱ͸ 1.1.Dockerͷجૅ֓೦ 1.2.Dockerͷߟ͑ʹ৮ΕΔ 2. DockerΛར༻͢Δҙٛ 2.1.؀ڥࠩҟ͔Βͷ୤٫ 2.2.ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞

  31. Dockerͷߟ͑ํʹ;ΕΔ • ࣮ࡍʹDockerΛ࢖ͬͯΈΔ ‣ Dockerfile౳Λॻ͍ͯΈΔ͜ͱͰงғؾΛ௫Ή ‣ ͲͷΑ͏ʹಈ࡞͍ͯ͠Δͷ͔Πϝʔδ͢Δ • ࠓճ͸؆୯ͳγΣϧεΫϦϓτΛ࣮ߦ͢Δ͚ͩͷΠϝʔ δΛ࡞੒࣮͠ߦ

  32. Dockerͷߟ͑ํʹ;ΕΔ • ·࣮ͣߦ͢ΔγΣϧεΫϦϓτΛॻ͘ ‣ ࠓճ͸, ඪ४ग़ྗʹ”Hello, world”Λग़ྗ͢Δ ‣ “helloworld”ͱ͍͏ϑΝΠϧ໊Ͱอଘ 1

    #!/bin/sh 2 3 echo "Hello, world";
  33. Dockerͷߟ͑ํʹ;ΕΔ • DockerfileΛ࡞੒͢Δ ‣ ࢖༻͢ΔosΠϝʔδ΍, Πϯετʔϧ͕ඞཁͳύο έʔδ, ίϐʔ͢ΔϑΝΠϧͳͲΛهड़ ‣ γΣϧεΫϦϓτͱಉ͡֊૚ʹҎԼͷ಺༰

    Λ”Dockerfile”ͱ͍͏໊લͰอଘ FROM ubuntu:16.04 COPY helloworld /usr/local/bin RUN chmod +x /usr/local/bin/helloworld CMD ["helloworld"]
  34. Dockerͷߟ͑ํʹ;ΕΔ FROM ubuntu:16.04 COPY helloworld /usr/local/bin RUN chmod +x /usr/local/bin/helloworld

    CMD ["helloworld"] %PDLFSΠϝʔδ 04 Λࢦఆ ࠓճ͸VCVOUVͷΛ࢖༻ ϑΝΠϧΛίϐʔ γΣϧίϚϯυΛ࣮ߦ ίϯςφͱ࣮ͯ͠ߦ͢Δલʹ ࣮ߦ͍ͨ͠ίϚϯυΛهड़ • DockerϑΝΠϧͷߏ੒
  35. Dockerͷߟ͑ํʹ;ΕΔ • ࣮ߦ
 ·ͣ͸ίϯςφΛϏϧυ͢Δ 1 $ docker image build -t

    helloworld:latest . 2 Sending build context to Docker daemon 3.072kB 3 Step 1/4 : FROM ubuntu:16.04 4 ---> 5e8b97a2a082 5 Step 2/4 : COPY helloworld /usr/local/bin 6 ---> f21bf7b10524 7 Step 3/4 : RUN chmod +x /usr/local/bin/helloworld 8 ---> Running in 915c2aeac8fa 9 Removing intermediate container 915c2aeac8fa 10 ---> 879dda6427e0 11 Step 4/4 : CMD ["helloworld"] 12 ---> Running in fa5dee022556 13 Removing intermediate container fa5dee022556 14 ---> 6b9e6c2ffc9e 15 Successfully built 6b9e6c2ffc9e 16 Successfully tagged helloworld:latest docker image build -t helloworld:latest . ϐϦΦυ๨Εʹ஫ҙ ͏·͘Ͱ͖͍ͯͦ͏ʁ ࣮ߦ݁Ռ
  36. Dockerͷߟ͑ํʹ;ΕΔ • ࣮ߦ
 ίϯςφΛ૸ΒͤΔ docker container run helloworld:latest 1 $

    docker container run helloworld:latest 
 2 Hello, world ࣮ߦ݁Ռ l)FMMP XPSMEz͕ग़ྗ͞Ε͍ͯΔ ࣮ߦʹඞཁͳϑΝΠϧ΍ΞϓϦέʔγϣϯΛDockerΠϝʔδʹಉ࣮ࠝͯ͠ߦ͢Δ.
  37. ໨࣍ 1. Dockerͱ͸ 1.1.Dockerͷجૅ֓೦ 1.2.Dockerͷߟ͑ʹ৮ΕΔ 2. DockerΛར༻͢Δҙٛ 2.1.؀ڥࠩҟ͔Βͷ୤٫ 2.2.ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞

  38. DockerΛར༻͢Δҙٛ • ͔ͭͯͷ։ൃελΠϧ͔ΒDockerΛ༻͍ͨ։ൃελΠϧ ʹγϑτ͢Δཧ༝ͱ͸ͳΜͩΖ͏͔ʁ ‣ ෆมͳ࣮ߦ؀ڥ(Immutable Infrastructure)ʹΑΔႈ౳ ੑͷ֬อ ‣ ࣮ߦ؀ڥߏங,

    ߏ੒ͷίʔυԽ(Infrastructure as Code) ‣ ϙʔλϏϦςΟ ‣ ΞϓϦέʔγϣϯ΍ϛυϧ΢ΣΞͷߏ੒؅ཧͷ༰қ͞
  39. ໨࣍ 1. Dockerͱ͸ 1.1.Dockerͷجૅ֓೦ 1.2.Dockerͷߟ͑ʹ৮ΕΔ 2. DockerΛར༻͢Δҙٛ 2.1.؀ڥࠩҟ͔Βͷ୤٫ 2.2.ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞

  40. ؀ڥࠩҟ͔Βͷ୤٫ • σϓϩΠઌͷαʔό͕ෳ਺ଘࡏ ‣ ͢΂ͯͷαʔό͕ಉ͡ઃఆͰ͋Δͱ͸ݶΒͳ͍ - σϓϩΠઌͷαʔόʹΑͬͯڍಈ͕มΘΔՄೳੑ → ݪҼɿՄมతͳΠϯϑϥΛڐ༰͍ͯ͠ΔͨΊ ΞϓϦέʔγϣϯαʔόA

    ΞϓϦέʔγϣϯαʔόB ΞϓϦέʔγϣϯαʔόC C͚ͩઃఆ࿙Ε͕͋ͬͨ…
  41. ؀ڥࠩҟ͔Βͷ୤٫ • ΞϓϦέʔγϣϯ͸ৗʹԿ͔ʹґଘ͍ͯ͠Δ ‣ OS, CPU, ϝϞϦ, ݴޠϥϯλΠϜ, ϥΠϒϥϦ… •

    ͜ͷґଘ౓ΛͳΔ΂͘Լ͛Δ͜ͱͰ͜ͷ໰୊Λղܾ • ղܾํ๏ ‣ Infrastructure as CodeʢΠϯϑϥͷߏ੒؅ཧʣ ‣ Immutable InfrastructureʢෆมͳΠϯϑϥʣ
  42. Infrastructure as Code • Infrastructure as Code(IaC, Πϯϑϥͷߏ੒؅ཧ) ‣ ΠϯϑϥΛίʔυϕʔεͰ؅ཧ͠Α͏ͱ͍͏ߟ͑

    • ҎԼͷ಺༰ΛίʔυͰهड़ ‣ ͲͷΑ͏ͳαʔόߏ੒ʹ͢Δ͔ ‣ ͲͷύοέʔδΛΠϯετʔϧ͢Δͷ͔ • ਓ͕खಈͰߦ͏ͷͰ͸ͳ͘, Chef΍Ansibleͱ͍ͬͨ πʔϧΛ࢖ͬͯࣗಈԽΛߦ͏
  43. Infrastructure as Code • ͨͩ͠, IaC΋ສೳͰ͸ͳ͍ ‣ ྫ͑͹, ͋Δπʔϧͷstable൛Λಋೖ͍ͨ͠ͱ͖ʹ, λ

    ΠϛϯάʹΑͬͯ͸ಋೖ͞ΕΔόʔδϣϯ͕ҟͳΔ - ͜ΕΛ͚͞Δʹ͸, ႈ౳ੑ͕อূ͞ΕΔίʔυΛॻ ͘ඞཁ͕͋Δ - ႈ౳ੑ
  44. Infrastructure as Code • ႈ౳ੑͱ͸
 
 
 
 
 •

    ௚ײతͳཧղͱͯ͠͸, ಉ͡ૢ࡞ΛԿ౓ߦͬͯ΋ಉ͡ঢ়ଶͰ͋Δ ͜ͱ • ෳ਺ճࣗಈԽεΫϦϓτΛ࣮ߦͯ͠΋, ৗʹαʔόͷঢ়ଶ͕ಉ͡ Ͱ͋Δ৔߹, ႈ౳ੑ͕อͨΕ͍ͯΔͱߟ͑ΒΕΔ ႈ౳ੑͱ͸ʮԿ౓ಉ͡ૢ࡞Λͨ͠ͱͯ͠΋ಉ݁͡ՌΛಘΒΕΔʯͱ͍͏΋ͷ Ͱ͢ɻྫ͑͹ʮabcͱ͍͏ϢʔβʔΛࢦఆͷଐੑͰ࡞੒ͤΑʯͱ͍͏ʮϓϩ άϥϜʯΛ͋ͬͨͱ͠·͢ɻ͜ͷʮϓϩάϥϜʯΛԿճ࣮ߦͨ͠ͱͯ͠΋ɺ ʮabcʯͱ͍͏Ϣʔβʔ͕ࢦఆͷଐੑͰ࡞੒͞Ε͍ͯΔͱ͍͏݁ՌʹมΘΓ ͸ͳ͍ͱ͍͏ࣄͰ͢ɻͭ·ΓઌͷྫͰݴ͑͹ɺύοέʔδ͕Πϯετʔϧࡁ ΈͳΒ͹ʮԿ΋͠ͳ͍ʯͷ͕๬·͍͠ಈ͖ʹͳΓ·͢ɻ Ҿ༻ɿhttp://www.intellilink.co.jp/article/column/devops02.html
  45. Infrastructure as Code • Chef΍AnsibleͰ΋ႈ౳ੑΛอͬͨΠϯϑϥΛߏ੒͢Δ ͜ͱ͸Մೳ ‣ ࣮ࡍ͸࣮૷࣍ୈͳͱ͜Ζ͕͋Γ, ׬શʹอূ͸͞Εͯ ͍Δͱ͍͏Θ͚Ͱ͸ͳ͍

    ‣ ৗʹႈ౳ੑ͕อূ͞Ε͍ͯΔίʔυΛॻ͖ଓ͚Δͷ͸ ӡ༻্େ͖ͳෛ୲ͱͳΓಘΔ - ͦ͜ͰImmutable Infrastructure͕ొ৔
  46. Immutable Infrastructure • Immutable Infrastructure(ෆมͳΠϯϑϥ)
 ͋Δ࣌఺ͷαʔόͷঢ়ଶΛอଘ͓͖ͯ͠, ͍ͭͰ΋ෳ੡ ΛՄೳʹ͓ͯ͘͠ ‣ ਖ਼͘͠ಈ࡞͍ͯ͠Δঢ়ଶΛอଘ͓͚ͯ͠͹,

    ෳ੡ͨ͠ αʔό΋ಉ༷ʹಈ࡞͢Δ͜ͱ͕อূ͞ΕΔ ‣ αʔόͷมߋ͸, طଘͷαʔόʹखΛՃ͑ΔͷͰ͸ͳ ͯ͘৽͍͠Πϝʔδͱͯ͠อଘ͢Δ
  47. IaCͱImmutable Infrastructure • Docker͸, IaCͱImmutable InfrastructureΛ௿ίετ͔ ͭ؆୯ʹ࣮ݱ͢Δ͜ͱ͕Մೳ ‣ DockerfileʹΑͬͯߏ੒Λ؅ཧ(IaC) ‣

    OS෦෼ͷଟ͘ΛϗετOSͱڞ༗͍ͯ͠ΔͨΊ, ىಈ ͕ඇৗʹߴ଎ͳͨΊ, ৽͘͠Πϯϑϥߏ੒Λ࡞Γ௚͢ Immutable Infrastructureͱ૬ੑ͕ྑ͍
  48. DockerͷϙʔλϏϦςΟ • ௨ৗ, ࡞੒ͨ͠ΞϓϦέʔγϣϯΛผͰ༻ҙͨ͠αʔό (Πϯϑϥ)্ʹల։͢Δ͜ͱͰαʔϏεΛӡ༻ ‣ ΞϓϦέʔγϣϯͱΠϯϑϥ͕׬શʹ෼཭ ‣ αʔό෦෼ͷઃఆͷࠩҟͳͲ͕ੜ·ΕΔՄೳੑ •

    Dockerίϯςφʹ͸, OS(Πϯϑϥ)ͱΞϓϦέʔγϣϯ ΛηοτͰϏϧυՄೳ ‣ Ϗϧυͨ͠Πϝʔδ͸ৗʹಉ͡ͳͷͰ, Docker͕Πϯε τʔϧ͞Ε͍ͯΔϚγϯͰ͋Ε͹ಉ͡؀ڥΛ࠶ݱՄೳ
  49. ໨࣍ 1. Dockerͱ͸ 1.1.Dockerͷجૅ֓೦ 1.2.Dockerͷߟ͑ʹ৮ΕΔ 2. DockerΛར༻͢Δҙٛ 2.1.؀ڥࠩҟ͔Βͷ୤٫ 2.2.ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞ 2.3.ຊ൪؀ڥͰͷDocker

    2.4.৽͍͠։ൃελΠϧ΁
  50. ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞ • Ұఆͷن໛ͷWebΞϓϦέʔγϣϯʹͳΔͱ, ෳ਺ͷ αʔϏε͕ڠௐͯ͠ಈ࡞͢Δ ‣ Webαʔό΍DBαʔό, ΩϟογϡαʔόͳͲ • DockerͰ͜ͷγεςϜΛ࠶ݱ͍ͨ͠

    ‣ σϓϩΠ͸༰қʹͳ͕ͬͨ, ࣮ߦॱ΍ίϯςφಉ࢜ͷ ґଘؔ܎ͱ͍ͬͨ໰୊͕͋Δ - Docker ComposeΛ࢖ͬͯղܾ
  51. ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞ • Docker Compose
 ෳ਺ͷίϯςφΛ࢖͏DockerΞϓϦέʔγϣϯΛఆ ٛɾ࣮ߦ͢ΔͨΊͷπʔϧ ‣ yamlܗࣜͰΞϓϦέʔγϣϯΛఆٛ 1 version:

    "3" 2 services: 3 web: 4 image: gihyodocker/web 5 ports: 6 - "3000:3000" 7 environment: 8 REDIS_TARGET: redis 9 depends_on: 10 - redis 11 12 redis: 13 image: "redis:alpine"
  52. ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞ 1 version: "3" 2 services: 3 web: 4 image:

    gihyodocker/web 5 ports: 6 - "3000:3000" 7 environment: 8 REDIS_TARGET: redis 9 depends_on: 10 - redis 11 12 redis: 13 image: "redis:alpine" ←࢖༻͢ΔDockerΠϝʔδ ←ϙʔτϑΥϫʔσΟϯά ←؀ڥม਺ ←ґଘؔ܎
 (webͷલʹredisΛىಈ) ←KVSͷىಈ
  53. ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞ • ࣮ࡍ͸, ͜ͷߏ੒Λෳ਺୆༻ҙ͢Δ͜ͱ΋͋Δ ‣ ෛՙରࡦͰεέʔϧΞ΢τ͢Δ৔߹ͳͲ LoadBalancer αʔό
 (Dockerϊʔυ) ←docker-compose.ymlΛద༻

    ←docker-compose.ymlΛద༻ ←docker-compose.ymlΛద༻ ͨͩ͠, Docker Compose୯ମ͸, 1ͭͷαʔόͰͷ࢖༻Λ૝ఆ →ෳ਺୆࢖͑ΔΑ͏ʹ͍ͨ͠
  54. ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞ • Docker Swarm
 ୯Ұͷαʔό͚ͩͰͳ͘, ෳ਺ͷαʔόΛ·͍ͨͰ؅ཧ Ͱ͖ΔΑ͏ʹͨ͠΋ͷ ‣ Docker ComposeͰͷෳ਺ͷίϯςφͷ؅ཧ

    ‣ ίϯςφ਺ͷ૿ݮ(εέʔϦϯά) ‣ ϩʔϦϯάΞοϓσʔτ etc…
  55. ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞ • ίϯςφΦʔέετϨʔγϣϯ
 ෳ਺ͷϊʔυΛލ͍ͩίϯςφͷ؅ཧΛߦ͏͜ͱ • ίϯςφΦʔέετϨʔγϣϯπʔϧ
 ΦʔέετϨʔγϣϯΛ࣮ݱ͢ΔͨΊͷπʔϧ ‣ Docker Swarm

    ‣ Kubernetes ͳͲ https://github.com/docker/swarm https://github.com/kubernetes/kubernetes/tree/master/logo
  56. ໨࣍ 1. Dockerͱ͸ 1.1.Dockerͷجૅ֓೦ 1.2.Dockerͷߟ͑ʹ৮ΕΔ 2. DockerΛར༻͢Δҙٛ 2.1.؀ڥࠩҟ͔Βͷ୤٫ 2.2.ΞϓϦέʔγϣϯߏ੒؅ཧͷ͠΍͢͞