Docker入門

Add1036688abcb2e3dbff7c3090f7e35?s=47 imtnd
April 24, 2016

 Docker入門

NaITE 13回目勉強会 Docker入門 資料

Add1036688abcb2e3dbff7c3090f7e35?s=128

imtnd

April 24, 2016
Tweet

Transcript

  1. Docker ೖ໳ NaITE #13 2016.4.27

  2. ࣗݾ঺հ ໊લɿ֯ాɹढ़ʢͭͷͩɹ͠ΎΜʣ ίϛϡχςΟɿNaITEɹͳͲ Twitterɿ͍ΉͯΜˏimtnd ۈ຿ઌɿ௨৴ܥ੡଄ۀ ۀ຿ɿιϑτ΢ΣΞ։ൃɹ5೥໨

  3. Docker         

        
  4. ຊηογϣϯͷ໨త DockerΛͳΜͱͳ͘ཧղ͢Δ DockerΛ࠷௿ݶ࢖͑ΔΑ͏ʹͳΔ

  5. Docker

  6. Dockerʹ͍ͭͯ Dockerͱ͸ɺԾ૝Խٕज़ͷҰͭ ίϯςφͱ͍͏୯ҐͰԾ૝Խ͢Δ͜ͱʹΑΓɺ OSͳͲʹґଘ͠ͳ͍γεςϜΛఏڙ

  7. Dockerʹ͍ͭͯ Virtual Machine container https://www.docker.com/what-docker

  8. DockerͷϝϦοτ VMͱҧ͍ܰྔͰ͋Γɺىಈɺऴ͕ྃߴ଎Ͱ ͋Δ CIͳͲͰ࢖͍ࣺͯͳ͕ΒΫϦʔϯͳ؀ڥͰς ετ͢Δ͜ͱ͕Ͱ͖Δ ύοέʔδΠϝʔδ͕ڞ༗Ͱ͖ɺ͙͢ʹ࢖༻ ͢Δ࢓૊Έ͕͋Δ

  9. Docker Toolbox

  10. Docker Toolbox Dockerʹؔ࿈͢Δπʔϧ͕ύοέʔδԽ͞Ε ͨ΋ͷ Docker Engine Docker Machine Docker Compose

    Kitematic
  11. DockerͷΠϯετʔϧํ๏ Cent OS 7 Ҏ্ yum ͰΠϯετʔϧՄೳ Ubuntu 15.04 Ҏ্

    ύοέʔδΛ௥Ճͯ͠ɺapt-getͰΠϯε τʔϧՄೳ https://docs.docker.com/engine/installation/linux/ubuntulinux/
  12. DockerͷΠϯετʔϧํ๏ ίϯςφઐ༻OS https://coreos.com/using-coreos/containers/

  13. DockerͷΠϯετʔϧํ๏ ίϯςφઐ༻OS CoreOS Project Atomic Red Hat Enterprise Linux Atomic

    Host Snappy Ubuntu Core
  14. DockerͷΠϯετʔϧํ๏ WindowsɺMac OSͷ৔߹ Virtual Box Docker Toolbox ※ɹ2016/04/27ݱࡏͷϝδϟʔͳํ๏

  15. DockerͷΠϯετʔϧํ๏ MacOSͱWindowsͷωΠςΟϒԾ૝ԽΛ༻͍ͨ Docker७ਖ਼πʔϧʮDocker for Mac/Windowsʯొ৔ɺ VirtualBox͸ෆཁʹ http://www.publickey1.jp/blog/16/docker_for_macwindows.html

  16. WindowsɺMac OSͰԿ΋ߟ͑ͳ͍ͰΠϯε τʔϧ͢ΔͱɺVIrtual Box্ʹ”default”ͱ͍ ͏Ծ૝Ϛγϯ͕Ͱ͖͍ͯΔ Linuxͷ৔߹͸ίϚϯυͰɺDocker༻ͷԾ૝ ϚγϯΛ࡞੒͢Δ DockerͷΠϯετʔϧํ๏

  17. Docker Machine

  18. Docker Machine Docker ϗετΛϚωδϝϯτ͢Δπʔϧ Docker ϗετͷ࡞੒ Docker ϗετͷىಈ Docker ϗετͷऴྃɹɹɹͳͲ

  19. Docker MachineίϚϯυ Docker MachineΛVirtual Box্ʹ࡞੒ Docker Machineͷ࡟আ $docker-machine create —driver

    virtualbox vmD(Ծ૝Ϛγϯ໊) $docker-machine rm vmD(Ծ૝Ϛγϯ໊)
  20. Docker MachineίϚϯυ Dockerϗετͷىಈ Dockerϗετͷऴྃ DockerϗετͷҰཡදࣔ $docker-machine start default(Ծ૝Ϛγϯ໊) $docker-machine stop

    default(Ծ૝Ϛγϯ໊) $docker-machine ls
  21. Docker MachineίϚϯυ DockerϗετͷIPΞυϨε֬ೝ Dockerϗετ΁ͷϩάΠϯ Dockerϗετͷ؀ڥม਺֬ೝ $docker-machine ip default(Ծ૝Ϛγϯ໊) $docker-machine ssh

    default(Ծ૝Ϛγϯ໊) $docker-machine env default(Ծ૝Ϛγϯ໊)
  22. DockerίϚϯυ DockerͷΠϝʔδͷऔಘ $docker pull centos:centos6 ϦϙδτϦ໊ λά

  23. DockerίϚϯυ $docker pull centos:centos6 DockerϨδετϦʹ ެ։͞Εͨ DockerΠϝʔδ pull

  24. DockerϨδετϦ DockerϨδετϦͱ͸ɺDockerͷΠϝʔδΛ ؅ཧ͓ͯ͘͠৔ॴ ެࣜͰ༻ҙ͍ͯ͠ΔDockerϨδετϦ͸ Docker Hub https://hub.docker.com/

  25. DockerίϚϯυ Docker ΠϝʔδͷҰཡදࣔ Docker Πϝʔδͷ࡟আ $docker images $docker rmi centos:centos6(ϦϙδτϦ໊:λά)

  26. DockerίϚϯυ Cent OSͷDockerΠϝʔδΛಈ͔ͯ͠ΈΔ $docker run -t -i —name centos centos:centos6

    /bin/bash ίϯςφ໊Λ෇͚ΒΕΔ
  27. DockerίϚϯυ Docker ίϯςφͷҰཡදࣔ Docker ίϯςφͷ࡟আ $docker ps -a $docker rm

    centos6(ίϯςφ໊)
  28. DockerίϚϯυ nginx(ΤϯδϯΤοΫε)ͷΠϝʔδऔಘ ϙʔτʹׂΓ෇͚ͯىಈ $docker pull nginx:latest $docker run -d -p

    8080:80 —name nginx nginx:latest WebαʔόΛಈ͔ͯ͠ΈΔ
  29. DockerίϚϯυ Docker ίϯςφͷऴྃ Docker ίϯςφͷىಈ $docker stop nginx(ίϯςφ໊) $docker start

    nginx(ίϯςφ໊)
  30. Dockerfile Dockerfileͱ͸ɺDockerΠϝʔδΛ࡞੒͢Δ ݩͱͳΔϑΝΠϧ makeϑΝΠϧͷΑ͏ͳ෺ͰɺҰίϚϯυͰ DockerΠϝʔδ͕࡞੒ग़དྷΔ ؆୯ʹهड़Ͱ͖ɺݟͨ໨΋ཧղ͠΍͍͢ͷ͕ ಛ௃

  31. Dockerfile Dockerfileαϯϓϧ $git clone https://github.com/imtnd/httpd.git httpd +- Dockerfile +- index.html

    ※ɹGit͕ͳ͍ਓ͸ϒϥ΢β͔Β௚઀ΞΫηε
  32. Dockerfile httpdσΟϨΫτϦʹҠಈ $cd httpd DockerfileΛݩʹDockerΠϝʔδͷ࡞੒ $docker build -t httpd ./

  33. Dockerfile ίϯςφͷىಈ $docker run -d -p 80:80 httpd(ϦϙδτϦ໊) ϒϥ΢βͰϗετͷIPΞυϨεʹΞΫηε͠ ͯΈΔͱɺ”hello

    docker”ͱݟ͑Δ
  34. Dockerfile FROM centos:centos6 MAINTAINER imtnd RUN yum install -y httpd

    ADD index.html /var/www/html/index.html EXPOSE 80/tcp CMD ["/usr/sbin/httpd","-D","FOREGROUND"]
  35. Dockerfile FROM centos:centos6 MAINTAINER imtnd RUN yum install -y httpd

    ADD index.html /var/www/html/index.html EXPOSE 80/tcp CMD ["/usr/sbin/httpd","-D","FOREGROUND"] ϕʔεͷDockerΠϝʔδ
  36. Dockerfile FROM centos:centos6 MAINTAINER imtnd RUN yum install -y httpd

    ADD index.html /var/www/html/index.html EXPOSE 80/tcp CMD ["/usr/sbin/httpd","-D","FOREGROUND"] DockerΠϝʔδ࡞੒ऀ
  37. Dockerfile FROM centos:centos6 MAINTAINER imtnd RUN yum install -y httpd

    ADD index.html /var/www/html/index.html EXPOSE 80/tcp CMD ["/usr/sbin/httpd","-D","FOREGROUND"] ίϚϯυͷ࣮ߦࢦࣔ
  38. Dockerfile FROM centos:centos6 MAINTAINER imtnd RUN yum install -y httpd

    ADD index.html /var/www/html/index.html EXPOSE 80/tcp CMD ["/usr/sbin/httpd","-D","FOREGROUND"] ϑΝΠϧͷ௥Ճࢦࣔ
  39. Dockerfile FROM centos:centos6 MAINTAINER imtnd RUN yum install -y httpd

    ADD index.html /var/www/html/index.html EXPOSE 80/tcp CMD ["/usr/sbin/httpd","-D","FOREGROUND"] ϙʔτ൪߸ͷొ࿥
  40. Dockerfile FROM centos:centos6 MAINTAINER imtnd RUN yum install -y httpd

    ADD index.html /var/www/html/index.html EXPOSE 80/tcp CMD ["/usr/sbin/httpd","-D","FOREGROUND"] ίϯςφىಈ࣌ͷ ࣮ߦίϚϯυࢦࣔ
  41. Docker Compose

  42. Docker Compose ίϯςφ͸αʔϏε୯ҐͰߏங͍ͯ͘͠ͱ؅ ཧָ͕ʹͳΔʢΞϓϦɺDBͳͲʣ αʔϏε͸ෳ਺ͷίϯςφʹΑͬͯߏங͞Ε Δ͜ͱʹͳΔͨΊҰׅͰ؅ཧ͢Δඞཁ͕͋Δ ෳ਺ͷίϯςϯΛ؅ཧग़དྷΔ࢓૊Έ͕ɺ Docker Compose

  43. Docker Compose Docker Compose͸ɺYMLϑΝΠϧͰίϯςφΛ؅ཧ ͢Δ YMLϑΝΠϧαϯϓϧ(TestLinkͱ͍͏αʔϏε͕ಈ͘) $git clone https://github.com/imtnd/testlink_yml.git ※ɹGit͕ͳ͍ਓ͸ϒϥ΢β͔Β௚઀ΞΫηε

  44. Docker Compose YMLϑΝΠϧΛݩʹαʔϏεΛىಈ ίϯςφͷঢ়ଶ֬ೝ $docker-compose up -d $docker-compose ps ԼهΞυϨεʹϒϥ΢β͔ΒΞΫηϧͰ͖Δ

    http://xxx.xxx.xxx.xxx(ϗετͷIPΞυϨε)/testlink/ ॳظઃఆͳͲ͸ԼهαΠτΛࢀর http://qiita.com/imtnd/items/a58a707db08c3710d963
  45. Docker Compose αʔϏεͷఀࢭ $docker-compose stop ҰίϚϯυͰɺMySQLɺTestLinkͷαʔϏε ͷίϯςφ͕ىಈͯ͠Δɻ busyboxͱ͍͏ͷ͸ɺσʔλΛӬଓԽ͢Δͨ Ίͷίϯςφ

  46. Docker Compose Docker hubʹ͋ΔΠϝʔδΛ࢖༻͢Δͱ໘౗ ͍͘͞ΠϯϑϥߏஙΛ͠ͳ͍Ͱɺ؀ڥΛηοτ Ξοϓ͢Δ͜ͱ͕Ͱ͖Δɻ ڵຯΛ࣋ͬͨπʔϧΛ؆୯ʹ࢖༻ͯ͠Έ͍ͨ࣌ ͳͲʹ࠷ద (πʔϧ໊)ɹdocker compose

  47. ͦͷଞπʔϧ Docker Swarm Docker Registory Kitematic

  48. ίϯςφؔ࿈αʔϏε tutum Kubernates

  49. ࠷ޙʹ Docker ͸·ͩ·ͩ·ͩ·ͩൃల్தͳπʔ ϧͰ͢ɻ ͜ͷεϥΠυͷ৘ใ΋աڈͷ෺ʹͳ͍͖ͬͯ ·͢ɻ ൃల్தͰ͋Δ͕ނʹɺ࠷৽ಈ޲Λ௥ͬͯΈ Δͱ໘ന͍ͱࢥ͍·͢ɻ

  50. Let’s Run Container