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

Docker勉強会

 Docker勉強会

Docker入門

Takashi Funato

July 12, 2017
Tweet

More Decks by Takashi Funato

Other Decks in Programming

Transcript

  1. Dockerͱ͸ 5 DockerΛࢧ͑ΔԾ૝Խٕज़ ϗετOSͷϦιʔεΛ࿦ཧతʹίϯςφ෼ׂ͠ ͯڞ༗ͯ͠࢖͏ɻܰྔͰߴ଎ͳͷ͕ಛ௃ɻ ίϯςφԾ૝Խٕज़ 2013೥ɺSolomon Hykesࢯ͕։ൃ͠ɺDockerࣾ ʢΞϝϦΧʣ͕ϝϯςφϯεΛଓ͚͍ͯΔɻGo Ͱॻ͔Ε͍ͯΔɻ

    ྺ࢙ ࠷ॳɺLinuxͷΈ͕ͩͬͨɺݱࡏ͸༷ʑͳ؀ڥͰಈ ͔͢͜ͱ͕ՄೳɻMacɺWindowsʢPCɼServerʣɺ AzureɺAWSɺGoogleCoudɺIBM BluemixͳͲɻ ಈ࡞؀ڥ DockerͷΠϝʔδΛ࡞੒ͯ͠͠·͑͹ɺଞͷಈ ࡞؀ڥ΁͍࣋ͬͯͬͯ΋ಉ͡Α͏ʹಈ࡞͢Δɻ ϙʔλϏϦςΟ(Ҡ২ੑ) ߏ੒ɺઃఆͳͲεΫϦϓτʹهड़͢Δ͜ͱͰɺ ॻ͔Εͨ௨Γͷߏ੒ΛࣗಈͰಉ͡΋ͷΛ࡞Δ͜ ͱ͕ग़དྷΔɻ infrastructure as code
  2. Dockerͱ͸ 6 ܰྔɺߴ଎Λࢧ͑ΔԾ૝Խͷجૅ஌ࣝ ैདྷͷߏ੒ͷαʔόɻҠ২ੑ௿ ͍ɻઃఆ͕໘౗ɻ ෺ཧαʔό ϗετOS্ͰɺߋʹԾ૝OSΛಈ͔͢ɻϦ ιʔε৯͏ɻॏ͍ɻVMWare Fusionɺ VirtualBoxɼParallelsɻHyperVisorܕ͸Ծ

    ૝ԽΛઐ༻ʹѻ͏ιϑτ΢ΣΞ͕OSͷ୅ ΘΓʹಈ͘ɻXen΍Hyper-VͳͲ ϗετܕԾ૝Խ ϗετOS্ʹ࿦ཧతͳ۠ըΛ࡞Γɺϓϩ ηεΛಈ͔͢࠷খݶͷϦιʔεΛ࢖͏ɻى ಈૣ͍ɻ͍ܰɻDockerɺSolarisContainer ίϯςφܕԾ૝Խ ϋʔυ΢ΣΞ OS ϓϩηε ϓϩηε ϋʔυ΢ΣΞ OS ήετOS ήετOS Ծ૝Խιϑτ ϓϩηε ϓϩηε ϓϩηε ϓϩηε ϋʔυ΢ΣΞ OS ίϯςφ ίϯςφ؅ཧιϑτ ϓϩηε ίϯςφ ϓϩηε ίϯςφ ϓϩηε ίϯςφ ϓϩηε
  3. Dockerͱ͸ 8 جຊػೳ ίϯςφΛಈ͔͢ ΠϝʔδΛݩʹɺࢦఆ͞Ε ͨ಺༰ͰɺίϯςφΛಈ͔ ͢ɻىಈɺఀࢭɺഁغͳͲ ͸ίϚϯυΛ࢖༻ͯ͠ߦ͏ɻ ΠϝʔδΛ ެ։ɾڞ༗

    ࡞੒ͨ͠ΠϝʔδΛϨδε τϦͱ͍͏ػೳͰɺެ։ɾ ڞ༗Λߦ͏ɻS3ϕʔεɺ঎ ༻ϕʔεͳͲɺ༷ʑͳํ๏ ͕͋ΔɻDockerHubͱ͍͏ ެࣜͷϨδετϦ͕͋Δɻ ΠϝʔδΛ࡞Δ ίϯςφΛಈ͔ͨ͢Ίͷ Libraryɺϛυϧ΢ΣΞɺ OSɺωοτϫʔΫઃఆͳ ͲΛ·ͱΊͯɺ̍ͭͷΠϝʔ δͱͯ͠࡞੒͢Δɻ
  4. DockerΛ࢖͏ 10 Πϯετʔϧ Mac • https://store.docker.com/ editions/community/docker-ce- desktop-mac • Requires

    Apple Mac OS Yosemite 10.10.3 or above. Download Docker Toolbox for previous OS versions.(https:// www.docker.com/products/ docker-toolbox) Windows PC • https://store.docker.com/ editions/community/docker-ce- desktop-windows • Requires Microsoft Windows 10 Professional or Enterprise 64-bit. For previous versions get Docker Toolbox.(https:// www.docker.com/products/ docker-toolbox)
  5. DockerΛ࢖͏ 11 Πϝʔδͷૢ࡞ʢൈਮʣ औಘͨ͠ΠϝʔδͷҰཡΛߦ͍· ͢ɻऔಘݩɺIDɺ࡞੒೔ɺαΠζ ͳͲ͕දࣔ͞Ε·͢ ΠϝʔδͷҰཡ # docker images

    औಘͨ͠Πϝʔδͷৄࡉ಺༰Λද ࣔ͠·͢ɻvolumeઃఆͳͲৄࡉද ࣔΛߦ͍·͢ɻ Πϝʔδͷৄࡉ಺༰ # docker inspect ${ΠϝʔδͷID} DockerHubʹొ࿥͞Ε͍ͯΔΠ ϝʔδΛݕࡧ͠·͢ɻDockerHub ͷαΠτΛݟͨ΄͏͕ૣ͍͔΋ Πϝʔδͷݕࡧ # docker search ݕࡧจࣈ औಘͨ͠ΠϝʔδΛ࡟আ͠·͢ɻ ࡟আ͢Δͱ໭ͤ·ͤΜɻ Πϝʔδͷ࡟আ # docker rmi ${ΠϝʔδͷID}
  6. DockerΛ࢖͏ 12 ίϯςφͷૢ࡞ʢൈਮʣ Πϝʔδ͔ΒίϯςφΛੜ੒ͯ͠ɺ ىಈޙɺϓϩηεΛಈ͔͠·͢ɻ ίϯςφͷੜ੒ / ىಈ # docker

    run ىಈͨ͠ίϯςφΛఀࢭ͠·͢ ίϯςφͷఀࢭ # docker stop ੜ੒͞ΕͨίϯςφΛىಈ͠·͢ɻ ίϯςφͷىಈ # docker start ίϯςφΛ࡟আ͠·͢ɻ࡟আ͢Δ ͱ໭ͤ·ͤΜɻ ίϯςφͷ࡟আ # docker rm ${ίϯςφID} ىಈ͍ͯ͠ΔίϯςφΛҰཡදࣔ ͠·͢ɻ-a Λ͚ͭΔͱఀࢭதͷί ϯςφ΋දࣔ͠·͢ ίϯςφͷҰཡ # docker ps [-a] ىಈ͍ͯ͠ΔίϯςφͰϓϩηε Λ࣮ߦ͠·͢ɻbashΛىಈͯ͠ɺ தΛ֬ೝͨ͠Γ͠·͢ɻ ىಈίϯςφͰϓϩηε࣮ߦ # docker exec [-it] ${ίϯςφID} ίϚϯυ
  7. DockerΛ࢖͏ 14 Ҿ͖͜΋ΓΛੈʹग़ͦ͏̍ Photo by Chinda Sam on Unsplash docker

    run --name sl -d -p 8000:8080 uzyexe/sl ͓·͑ਐḿ Ͳ͏ͳͷΑʁ And open http://localhost:8000/
  8. DockerΛ࢖͏ 16 Ҿ͖͜΋ΓΛੈʹग़ͦ͏̎ Photo by Jordan Hubbard on Unsplash docker

    run —name nginx-test -d -p 8800:80 -v /tmp:/var/log/nginx nginx:alpine And open http://localhost:8800/ ਐḿ ͳ͍σʔεɻ ͯ΁ check /tmp/access.log And
  9. DockerΛ࢖͏ 18 Dockerfile ࠷ॳ͔ΒDockerfileΛهड़͢Δͷ͸ѱखɻ Կ౓΋build͠ͳ͍ͰࡁΉΑ͏ʹ ίϯςφΛىಈͯ͠ɺͦͷதͰߦͬͨૢ࡞Λ هड़͢Δɻ ίϯςφૢ࡞ͷهड़ Dockerfile͸ϕʔεʹͳΔΠϝʔδʹ֤ϛυϧ΢Σ ΞΠϯετʔϧɺઃఆɺίϯςφͷىಈઃఆͳͲ

    ͷߏஙɾߏ੒؅ཧΛهड़͢Δɻdocker buildίϚϯ υͰDockerΠϝʔδΛ࡞੒ɻ͜ͷϑΝΠϧ͕͋Ε ͹ɺDockerΤϯδϯ͕ಈ͍͍ͯΔ৔ॴͰ͋Ε͹ɺ Πϝʔδͷ࡞੒͕ՄೳɻͲ͜Ͱ΋ಉ͡Πϝʔδ͕ ࡞੒͞ΕΔɻ https://github.com/dockerfile ϑΝΠϧͷαϯϓϧ খ͍͞αΠζͷϕʔεΠϝʔδ͔ຊ൪؀ ڥʹ͍ۙΠϝʔδΛ࢖༻͢Δɻ ϕʔεΠϝʔδ https://hub.docker.com/_/amazonlinux/ ϕʔεΠϝʔδ https://hub.docker.com/_/alpine/
  10. DockerΛ࢖͏ 19 Docker Compose ίϯςφΛ૊Έ߹ΘͤΔ ҰͭҰͭͷίϯςφΛίϚϯυ Ͱىಈ͢Δͷ͸൥ࡶͳͨΊɺى ಈ/ఀࢭ/ίϯςφ࡞੒/࡟আΛ Ұݩ؅ཧ͢Δ docker-compose

    ͱ͍͏ίϚϯυ͕͋Δɻ docker-compose.yml docker-compose.ymlͱ͍͏ ϑΝΠϧʹYAMLܗࣜͰهड़͢ Δɻෳ਺ͷίϯςφͷઃఆ಺༰ Λهड़͢ΔɻίϯςφؒͷϦϯ Ϋɺίϯςφؒͷ௨৴ɺσʔλ ؅ཧɺ؀ڥม਺ͳͲΛهड़ɻ ίϚϯυ docker-compose 
 up ίϯςφͷੜ੒ɾىಈ down ίϯςφͷ࡟আɾऴྃ start ίϯςφͷىಈ stop ίϯςφͷऴྃ