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

Brief description of Docker and XaaS in the AI era

Brief description of Docker and XaaS in the AI era

553d5f63a9ee17b37369c03437b3aece?s=128

MATSUKI Hidenori

May 23, 2019
Tweet

Transcript

  1. AI࣌୅ͷDocker+XaaS؆୯ཧղ MATSUKI Hidenori, DeNA AIγεςϜ෦ٕज़ڞ༗ձ May 23, 2019

  2. ࣗݾ঺հ • দ໦Ͱ͢ • https://github.com/mazgi • MLΤϯδχΞϦϯάάϧʔϓ • ே׆த 2

  3. ࠓ೔ͷ͓࿩ • Dockerͷ࿩ • ศར͞ͷ֬ೝʙMLฤʙ • Dockerͬ͘͟Γཧղ • Docker ComposeͰ΋ͬͱศརʹ

    • DockerfileʢͪΐͬͱʣϕετϓϥΫςΟε • XaaSʢβʔεʣͷ࿩ • ਎ۙͳXaaS • DockerͰGPUΛ࢖͏ͨΊͷIaaSͱIaC 3
  4. 4 ͦͷલʹ

  5. ͳͥ͜ͷςʔϚ͔ • զʑ͕΍Γ͍ͨ͜ͱ • ʮ͍ͭͰ΋Ͳ͜Ͱ΋ίϯϐϡʔλʔʹܭࢉ͍ͤͨ͞ʯ • ʮGPU΋ඞཁͳ͚ͩ࢖͍͍ͨʯ • ʮ҆શʹσʔλΛѻ͍͍ͨʯ •

    ࠓ೔͸⬆ Λ࣮ݱ͢ΔͨΊͷͬ͘͟Γͱͨ͠࿩Ͱ͢ 5
  6. Poll͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ 6 ʢ͝ଘ஌͔΋͠Ε·ͤΜ͕ʣ DockerΛΑΓศརʹ࢖͍ͬͯͨͩ ͚Δ Docker Compose ͱ IaaS ͷ

    ࿩Λ͠·͢ɻ
  7. Poll͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ 7 ϩʔΧϧʢMacʣͱIaaSͦΕͧΕ Ͱ࢖͑ΔαϯϓϧΛ༻ҙ͠·͠

  8. Poll͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ 8 ηογϣϯͷ࠷ޙʹͥͻ۩ମ తͳ಺༰Λڭ͍͑ͯͩ͘͞

  9. ࠓ೔ͷαϯϓϧ • Dockerfileଞαϯϓϧ • mazgi-sandbox/201905.note.brief-description-of-docker-and-xaas-in-the-ai-era • IaCαϯϓϧ • mazgi/terraform-aws-simple-vpc/tree/v2019.05.2 9

  10. ँࣙʗࢀߟࢿྉ ⏬ Λࢀߟʹ͍͖ͤͯͨͩ͞·ͨ͠ • ެࣜυΩϡϝϯτ https://docs.docker.com/ • ʮϚϯΨͰΘ͔ΔDockerʯγϦʔζ • #ϚϯΨͰΘ͔ΔDocker

    ᶃ https://llminatoll.booth.pm/items/825879 • #ϚϯΨͰΘ͔ΔDocker ᶄ https://llminatoll.booth.pm/items/1036317 • DockerΛࢧ͑Δٕज़ https://www.amazon.co.jp/dp/B00VHW3PKW 10
  11. 11 Dockerͷ࿩

  12. ศར͞ͷ֬ೝʙMLฤʙ Dockerͷ࿩ 12

  13. Docker͸ɾɾɾʁ • ؀ڥͷΠϝʔδԽ • ⬇ 1ߦͰ୭Ͱ΋Ͳ͜Ͱ΋TensorFlowͷಈ͘Jupyter Notebook͕ىಈͰ͖Δ • docker run

    -p 8888:8888 --rm -it tensorflow/tensorflow:latest-py3-jupyter 13
  14. Docker͸ɾɾɾʁ • “ίϯςφΠϝʔδ”ͷ࡞੒ɺڞ༗ɺ࣮ߦ͕Ͱ͖Δ • “Securely build, share and run any

    application, anywhere” • by https://www.docker.com/ • ͢Ͱʹଟ͘ͷίϯςφΠϝʔδ͕ڞ༗͞Ε͍ͯΔ • https://hub.docker.com/ ͳͲͰڞ༗Մೳ • ྫ: https://hub.docker.com/r/tensorflow/tensorflow/tags • ίϯςφΠϝʔδ͸શͯʮ࣮ߦՄೳͳLinuxʢͷίϯςφʣ؀ڥʯ 14
  15. Dockerͬ͘͟Γཧղ Dockerͷ࿩ 15

  16. Dockerͬ͘͟Γཧղ • “Linuxίϯςφ”ͱ͸ʁ ▶ ࣍ͷϖʔδͰਤΛ঺հ͠·͢ • ίϯςφͱ͸ҎԼͷ෼཭ • ϓϩηεۭؒ, ϑΝΠϧγεςϜ,

    ωοτϫʔΫ, ܭࢉϦιʔεʢCPU, Memʣ • VirtualBoxͷΑ͏ͳԾ૝ϚγϯʢVMʣͰ͸ͳ͍ • VM͸จࣈ௨Γϋʔυ΢ΣΞͷந৅Խ • pipͷΑ͏ͳιϑτ΢ΣΞύοέʔδͰ͸ͳ͍ • ιϑτ΢ΣΞύοέʔδ͸͋͘·Ͱʢ࣮ߦՄೳϑΝΠϧΛؚΉʣσʔλ • venvͷΑ͏ͳ؀ڥ੾Γସ͑πʔϧͰ͸ͳ͍ • ؀ڥ੾Γସ͑πʔϧ͸ओʹ؀ڥม਺ͳͲΛ੾Γସ͍͑ͯΔ 16
  17. Container Runtime Process(es) bin lib Container Runtime Process(es) bin lib

    Container Runtime Process(es) bin lib Container Runtime Process(es) bin lib Dockerͬ͘͟Γཧղ 17 HW OS OS(Guest) OS(Host) HW HyperVisor pip ͳͲ ෺ཧϚγϯ্ͰVMΛհͣ͞ʹ ίϯςφΛಈ͔͢͜ͱ΋Մೳ Docker for Mac, GKEͳͲ͸ VM্ͰίϯςφΛಈ͔͍ͯ͠Δ VirtualBox ͳͲ
  18. Dockerͬ͘͟Γཧղ • ࣮͸ίϯςφ≠Docker • DockerҎ֎ͷίϯςφٕज़΋͋Δ(LXC, Solaris Containers, etc.) • Ͱ͕͢ࠓ೔͸Dockerͷ࿩͚ͩ

    • Docker͸LinuxͷϦιʔε෼཭ػೳ(namespace)Λ࢖༻ • Mount namespace, PID namespace, etc. • https://en.wikipedia.org/wiki/Linux_namespaces • ͳͷͰDocker for Mac͸macOS্ͷLinux্Ͱಈ͍͍ͯΔ • https://blog.docker.com/2016/03/docker-for-mac-windows-beta/ 18
  19. Dockerͬ͘͟Γཧղ • Ͳ͏΍ͬͯΠϯετʔϧ͢Ε͹͍͍ͷʁ on macOS • ࣮͸⬇ ͷ2ίϚϯυ͚ͩͰΠϯετʔϧͰ͖·͢ • /usr/bin/ruby

    -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ master/install)" • brew cask install docker • ࢀߟ: https://brew.sh/ 19
  20. Docker ComposeͰ΋ͬͱศརʹ Dockerͷ࿩ 20

  21. Docker ComposeͰ΋ͬͱศརʹ • Docker Composeͱ͸ʁ • ෳ਺ͷίϯςφΛ؅ཧͰ͖Δπʔϧ • Կ͕Ͱ͖Δͷʁ •

    ʢ౰વʣෳ਺ίϯςφͷ؅ཧ • ྫ: WebΞϓϦέʔγϣϯ։ൃͰϑϩϯτΤϯυ, αʔόʔαΠυ, DBΛಉ࣌ʹىಈ • mazgi-showcase/docker-compose.webapp-dev-envs/blob/2019.04.0/rails-webapp/ docker-compose.yml • ࠓ೔͸͋·Γ৮Ε·ͤΜ • ίϚϯυϥΠϯҾ਺ͷఆٛͱ؅ཧ • ʮdocker run …ͳΜ͚ͩͬʯͬͯͳΔ͜ͱͳ͍Ͱ͔͢ʁ • ͦΕɺYAMLܗࣜͰఆٛͰ͖·͢ɺ΋ͪΖΜGitͰόʔδϣϯ؅ཧՄೳ 21
  22. Docker ComposeͰ΋ͬͱศརʹ • ͔͜͜ΒεΫγϣଟΊͰ͍͖·͢ • ͕࣌ؒ͋Ε͹Demo΋͠·͢ • αϯϓϧʢ࠶ܝʣ • mazgi-sandbox/201905.note.brief-description-of-docker-and-xaas-in-the-ai-era

    22
  23. Docker ComposeͰ΋ͬͱศརʹ 23 sample-files/01.docker-compose-2.3-tensorflow/docker-compose.yml ⬇ ΛYAMLͰఆٛ - DockerΠϝʔδ໊ - ϙʔτϑΥϫʔυઃఆ

  24. Docker ComposeͰ΋ͬͱศརʹ 24 sample-files/02.docker-compose-2.3-tensorflow/docker-compose.yml ΠϝʔδͰ͸ͳ͘DockerfileΛϏϧυ Dockerfileͷத਎͸લϖʔδͱಉ͡ ※SHA256ϋογϡΛࢦఆ͢Δͱ࣮֬ʹಉ͡ ΠϝʔδΛݩʹͰ͖Δ sample-files/02.docker-compose-2.3-tensorflow/Dockerfile

  25. Docker ComposeͰ΋ͬͱศརʹ 25 sample-files/03.docker-compose-2.3-tensorflow/docker-compose.yml Dockerfileͷ໊લΛ”Dockerfile”Ҏ֎ʹ ͍ͨ͜͠ͱɺ͋Γ·͢ΑͶ sample-files/03.docker-compose-2.3-tensorflow/Dockerfile.03-2 ϑΝΠϧΛ௥Ճ͍ͨ͜͠ͱ͋Γ·͢ΑͶ

  26. Dockerfileʢͪΐͬͱʣ ϕετϓϥΫςΟε Dockerͷ࿩ 26

  27. DEMO DockerfileʢͪΐͬͱʣϕετϓϥΫςΟε 27 sample-files/04.docker-tensorflow/Dockerfile.04-01.unfavorable sample-files/04.docker-tensorflow/Dockerfile.04-02.favorable ͍ͭ”RUN”໋ྩΛԿߦ΋ॻ͍ͯ͠·͍ ·͕͢”RUN”͝ͱʹϨΠϠʔ͕࡞ΒΕ ΠϝʔδαΠζ͕૿͑ΔͷͰྑ͋͘Γ ·ͤΜɻ “RUN”໋ྩΛͰ͖Δ͚ͩগͳ͘͢Δ͜

    ͱͰॏͳΔϨΠϠʔΛݮΒ͢͜ͱ͕Ͱ ͖·͢ɻ
  28. DEMO DockerfileʢͪΐͬͱʣϕετϓϥΫςΟε 28 sample-files/05.docker-tensorflow/Dockerfile.05-01.fail build࣌ʹϓϥΠϕʔτϦϙδτϦ͔Β git clone͍ͨ͜͠ͱ͋Γ·͢ΑͶ Ͱ΋݁Ռ͸ɾɾɾ伴͕ͳ͍ͨΊcloneͰ͖·ͤΜ Permission denied

    (publickey). fatal: Could not read from remote repository.
  29. DEMO DockerfileʢͪΐͬͱʣϕετϓϥΫςΟε 29 sample-files/05.docker-tensorflow/Dockerfile.05-02.insecure ͦΜͳ࣌ɺ”COPY”໋ྩͰ伴ϑΝΠϧ Λίϐʔ͢Ε͹buildதʹgit cloneͰ͖ ·͕͢ɺ͜Ε͸ةݥͰ͢ʂ “COPY”ͷϨΠϠʔΛࢦఆͯ͠؆୯ʹ伴ϑΝΠϧ ΛऔΓग़͢͜ͱ͕Ͱ͖ͯ͠·͍·͢ɻ

    ܁Γฦ͠·͕͢ɺ͜Ε͸ͱͯ΋ةݥͰ͢ʂ Ͱ΋“COPY”ͷ࣌ʹ࡞ΒΕͨϨΠϠʔ ͸͔ͬ͠Γͱ࢒͍ͬͯ·͢ɻ
  30. DEMO DockerfileʢͪΐͬͱʣϕετϓϥΫςΟε 30 sample-files/05.docker-tensorflow/Dockerfile.05-03.secure-with-buildkit ͦ͜Ͱ”RUN”໋ྩʹΦϓγϣϯΛ ౉ͤΔΑ͏ʹͳΓ·ͨ͠ɻ build࣌ʹ΋͜ͷΑ͏ͳࢦఆΛ͢Δඞཁ͕͋Γ·͢ DOCKER_BUILDKIT=1 docker build

    . \ —secret id=github_private_key,src=$(pwd)/.ssh/deploy-key.id_rsa \ -f Dockerfile.05-03.secure-with-buildkit
  31. 31 XaaSʢβʔεʣͷ࿩

  32. ਎ۙͳXaaS XaaSʢβʔεʣͷ࿩ 32

  33. ਎ۙͳXaaS • XaaS == Anything as a ServiceɺIaaS, FaaS, SaaS

    ͳͲͷ૯শ • IaaS == Infrastructure as a Service • αʔόʔϋʔυ΢ΣΞͷαʔϏεԽ • Ϣʔβʔ͸OSͱωοτϫʔΫΛѻ͑Δ • FaaS == Function as a Service • ʢϓϩάϥϛϯάతҙຯͷʣؔ਺࣮ߦ؀ڥͷαʔϏεԽ • Ϣʔβʔ͸ؔ਺Λఆ࣮ٛ͠ߦͰ͖Δ • SaaS == Software as a Service • ΞϓϦέʔγϣϯͷαʔϏεԽ • Ϣʔβʔ͸ʢWebϒϥ΢βӽ͠ʹʣܾ·ͬͨΞϓϦέʔγϣϯΛ࢖༻Ͱ͖Δ 33
  34. ??? Process(es) bin lib ??? Process(es) bin lib ਎ۙͳXaaS 34

    OS(Guest) OS(Host) HW HyperVisor ??? Process(es) bin lib Data IaaS FaaS SaaS VMҎԼΛ͓೚ͤ ΞϓϦ࣮ߦ؀ڥ·Ͱ͓೚ͤ σʔλҎ֎શ෦͓೚ͤ Gmail AWS Lambda Cloud Functions Google Calendar AWS EC2 GCP GCE ౰વϋʔυ΢ΣΞ͕ ͋Δ”͸ͣ”ɻ ͖ͬͱLinuxͳͲ͕ ಈ͍͍ͯΔ”͸ͣ”ɻ ΋͸΍Ϣʔβʔ͔Β͸ ࢓૊Έ͕ݟ͑ͳ͍ɻ
  35. ਎ۙͳXaaS 35 https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html ྫ͑͹AWS Lambda͸Amazon LinuxͰಈ͍͍ͯΔɻ

  36. DockerͰGPUΛ࢖͏ͨΊͷ IaaSͱIaC XaaSʢβʔεʣͷ࿩ 36

  37. DockerͰGPUΛ࢖͏ͨΊͷIaaSͱIaC • զʑ͕΍Γ͍ͨ͜ͱ • ʮ͍ͭͰ΋Ͳ͜Ͱ΋ίϯϐϡʔλʔʹܭࢉ͍ͤͨ͞ʯ • ʮGPU΋ඞཁͳ͚ͩ࢖͍͍ͨʯ • ʮ҆શʹσʔλΛѻ͍͍ͨʯ •

    ⬆ Λ࣮ݱ͢ΔͨΊʹඞཁͳͷ͸ɾɾɾʁ 37
  38. DockerͰGPUΛ࢖͏ͨΊͷIaaSͱIaC • ʮ͍ͭͰ΋Ͳ͜Ͱ΋ίϯϐϡʔλʔʹܭࢉ͍ͤͨ͞ʯ • IaaSͰੈքதͲ͔͜ΒͰ΋Ծ૝Խ͞Εͨίϯϐϡʔλʔ͕࢖͑Δ✅ • DockerΛ࢖͑͹؀ڥΛ؆୯ʹ࠶ݱͰ͖Δ✅ • IaaSʹDockerͷΠϯετʔϧ͕ඞཁɾɾɾʁ 38

  39. DockerͰGPUΛ࢖͏ͨΊͷIaaSͱIaC • ʮGPU΋ඞཁͳ͚ͩ࢖͍͍ͨʯ • IaaSͰେྔʹGPUΛ࢖͑Δ✅ • Docker͔ΒGPUͬͯͲ͏΍ͬͯ࢖͑͹ɾɾɾʁ 39

  40. DockerͰGPUΛ࢖͏ͨΊͷIaaSͱIaC • ʮ҆શʹσʔλΛѻ͍͍ͨʯ • IaaSͳΒ͍ͭ͘Ͱ΋ִ཭ͨ͠؀ڥ࡞Εͯ҆શ✅ • Ͱ΋ͦͷ··Ͱ͸ੈքதͲ͔͜ΒͰ΋ΞΫηεͰ͖ͯ͠·͏ͷͰ͸ɾɾɾʁ • ౎౓ִ཭ͨ͠؀ڥ࡞ΔͷେมͰ͸ɾɾɾʁ 40

  41. DockerͰGPUΛ࢖͏ͨΊͷIaaSͱIaC • IaC == Infrastructure as Code • ʮΠϯϑϥΛίʔυͰఆٛ͢Δʯߟ͑ํ •

    ίʔυͳͷͰ • όʔδϣϯ؅ཧͰ͖Δ • ෳ੡Ͱ͖Δ • ܁Γฦ͠΍෼ذ͕Ͱ͖Δʢݶఆతʣ • ଟ͘ͷπʔϧ͕͋Δ 41
  42. DEMO DockerͰGPUΛ࢖͏ͨΊͷIaaSͱIaC • αϯϓϧʢ࠶ܝʣ • https://github.com/mazgi/terraform-aws-simple-vpc/tree/v2019.05.2/examples/ simple-ml • ࠓճͷDemo ▶

    ࣍ͷϖʔδͰߏ੒ਤΛ঺հ͠·͢ • TerraformͰAWSΛઃఆ͢Δ • ಈը ▶ https://www.youtube.com/watch?v=aJiaQASr0G4 • AWSఏڙͷDeep LearningΠϝʔδ͔ΒԾ૝ϚγϯΛىಈ͢Δ • Ծ૝ϚγϯʢVMʣ΁ͷSSH઀ଓݩΛ೚ҙͷIPΞυϨεʹݶఆ͢Δ • VM্ͰDocker Composeͱnvidia-docker 2Λ࢖ͬͯTensorFlowίϯςφΛىಈ͢Δ • ϩʔΧϧ͔ΒWebϒϥ΢βͰDockerίϯςφ্ͷJupyter Notebookʹ઀ଓ͢Δ 42
  43. DEMO DockerͰGPUΛ࢖͏ͨΊͷIaaSͱIaC 43 AWS VPC https://network.yamaha.com/support/download/tool/ Your Place ( Office

    ) Other Places GPU Instance SSH HTTP SSH