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

Introduction to Docker

Yukiyan
October 16, 2015

Introduction to Docker

社内勉強会(2015/10/16)

Yukiyan

October 16, 2015
Tweet

More Decks by Yukiyan

Other Decks in Programming

Transcript

  1. Introduction to Docker

  2. Why choose this topic?

  3. Big Wave Coming

  4. Big Wave in ࣾ಺ • Docker swarmͷػӡ • Docker࣮ફೖ໳(Dockerຊ)ͷ޿·Γ •

    ๻ͷνʔϜʹDocker৬ਓ͕͍Δ
  5. Big Wave in the ੈք • Dockerʹؔ࿈༷ͨ͠ʑͳπʔϧͷొ৔ • Docker Machine

    • Docker swarm • Docker compose
  6. ·͍ͣ

  7. Goal • Dockerͷಛ௃ɾར఺Λཧղ͢Δ͜ͱ • DockerfileΛॻ͍ͯϏϧυ͢Δ·Ͱͷ؆୯ͳྲྀΕΛཧղ͢Δ ͜ͱ • Dockerʹ͓͚ΔσΟεΫΠϝʔδ؅ཧػೳɾϓϩηε؅ཧ

  8. Dockerͷಛ௃ɾར఺Λ ཧղ͢Δ

  9. What is Docker?

  10. What is Docker? • Dockerࣾ ͕ΦʔϓϯιʔεͰެ։͍ͯ͠Δɺίϯςφٕज़ʹ ΑΔԾ૝Խιϑτ΢ΣΞ • LXC(Linux Container),

    AUFS(Another Union FS) • Vagrant౳ͱൺֱͯ͠ىಈ͕଎͍ɻ
  11. What is Container?

  12. ※ ※ ը૾Ҿ༻ݩ: http://www.slideshare.net/TrisM/docker-41045742 P22

  13. Benefit • σϓϩΠ͕खܰʹͳΔ • εέʔϥϏϦςΟɾߴޮ཰ɾ൚༻ੑ

  14. Use Case • ΞϓϦέʔγϣϯ • DB • Ϗϧυ؀ڥ • ͍Ζ͍ΖͳΜͰ΋

    ※ ※ ը૾Ҿ༻ݩ: http://www.slideshare.net/TrisM/docker-41045742 P22
  15. DockerfileΛॻ͍ͯϏϧ υ͢Δ·Ͱͷ؆୯ͳྲྀΕ Λཧղ͢Δ

  16. flow 1. Dockerfileॻ͘ 2. Ϗϧυ͢Δ 3. docker run͢Δ 4. ϨδετϦ΁push

  17. 1. Dockerfileॻ͘ FROM yukiyan_w/centos:centos6 MAINTAINER Yuki Wakayama RUN yum -y

    install httpd RUN echo 'Hello, World!!' > /var/www/html/index.html ADD init.sh /usr/local/bin/init.sh RUN chmod u+x /usr/local/bin/init.sh CMD ["/usr/local/bin/init.sh"]
  18. #!/bin/bash service httpd start /bin/bash

  19. 2. Ϗϧυ͢Δ docker build -t yukiyan_w/apache:ver1.0 . Πϝʔδ͕Ͱ͖Δ docker@dev:~$ docker

    images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE yukiyan_w/apache ver1.0 e0bd562a2d43 1 days ago 264.1 MB yukiyan_w/centos centos6 a005304e4e74 1 days ago 203.1 MB
  20. 3. docker run͢Δ docker run -itd -p 8000:80 --name apache01

    yukiyan_w/apache:ver1.0 ಈ͍ͯΔ͔֬ೝ docker@dev:~$ docker attach apache01 [root@3a607e0dd9f9 /]# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 15:09 ? 00:00:00 /bin/bash /usr/local/bin/init.sh root 17 1 0 15:09 ? 00:00:00 /usr/sbin/httpd root 19 1 0 15:09 ? 00:00:00 /bin/bash apache 20 17 0 15:09 ? 00:00:00 /usr/sbin/httpd apache 21 17 0 15:09 ? 00:00:00 /usr/sbin/httpd apache 22 17 0 15:09 ? 00:00:00 /usr/sbin/httpd root 36 19 0 15:10 ? 00:00:00 ps -ef
  21. 4. ϨδετϦ΁push docker push yukiyan_w/apache

  22. flow • Dockerfileॻ͘ɺϏϧυ͢Δɺ docker runɺ͍͡Δɺcommitɺtag ͚ͭΔɺϨδετϦ΁ • DockerHub͔Βpull͢Δɺdocker runɺ͍͡Δɺcommitɺtag͚ͭΔɺ ϨδετϦ΁

    ※ ※ ը૾Ҿ༻ݩ: http://www.slideshare.net/TrisM/docker-41045742 P22
  23. Cache for Faster Builds • Docker͸ΠϝʔδΛࠩ෼؅ཧͯ͠ΔͷͰϏϧυ͕ૣ͍

  24. docker build -t yukiyan_w/apache:ver1.0 . Step 0 : FROM yukiyan_w/centos:centos6

    centos6: Pulling from yukiyan_w/centos Status: Downloaded newer image for yukiyan_w/centos:centos6 ---> a005304e4e74 Step 1 : MAINTAINER Yuki Wakayama ---> Running in 0eec2e2e93d1 ---> 2477c45cfa23 Removing intermediate container 0eec2e2e93d1 Step 2 : RUN yum -y install httpd ---> Running in 9dd64b9d2aeb ---> c09ed7b982db Removing intermediate container 9dd64b9d2aeb Step 3 : RUN echo 'Hello, World!!' > /var/www/html/index.html ---> Running in b8972fb573a7 ---> 9cd9b8077c76 Removing intermediate container b8972fb573a7 Step 4 : ADD init.sh /usr/local/bin/init.sh ---> 998ad3b60ab3 Removing intermediate container 23e41b8192c4 Step 5 : RUN chmod u+x /usr/local/bin/init.sh ---> Running in 2be75c857f5c ---> 5726cae34e32 Removing intermediate container 2be75c857f5c Step 6 : CMD /usr/local/bin/init.sh Successfully built e0bd562a2d4
  25. ͪΐͬͱม͑Δ FROM yukiyan_w/centos:centos6 MAINTAINER Yuki Wakayama RUN yum -y install

    httpd RUN echo 'Hello, World!!' > /var/www/html/index.html ADD init.sh /usr/local/bin/init.sh RUN chmod u+x /usr/local/bin/init.sh + RUN echo 'Hello, World!!' CMD ["/usr/local/bin/init.sh"]
  26. Step 0 : FROM yukiyan_w/centos:centos6 ---> a005304e4e74 Step 1 :

    MAINTAINER Yuki Wakayama ---> Using cache ---> 2477c45cfa23 Step 2 : RUN yum -y install httpd ---> Using cache ---> c09ed7b982db Step 3 : RUN echo 'Hello, World!!' > /var/www/html/index.html ---> Using cache ---> 9cd9b8077c76 Step 4 : ADD init.sh /usr/local/bin/init.sh ---> Using cache ---> 998ad3b60ab3 Step 5 : RUN chmod u+x /usr/local/bin/init.sh ---> Using cache ---> 5726cae34e32 Step 6 : RUN echo 'Hello, World!!' ---> Running in 4191d60ea4b0 Hello, World!! ---> c87043d1219f Removing intermediate container 4191d60ea4b0 Step 7 : CMD /usr/local/bin/init.sh ---> Running in 52aef5dab4ce ---> 042133d33472 Removing intermediate container 52aef5dab4ce Successfully built 042133d33472
  27. !

  28. But ⾠

  29. yum update໋ྩ΋Ωϟογϡ͞ΕΔͷͰ`--no-cacheͱ͔͠ͳ ͍ͱ࣍ճϏϧυ࣌ʹ࠷৽ͷঢ়ଶʹΞοϓσʔτ͞Εͳ͍

  30. Progress • Dockerͷಛ௃ɾར఺Λཧղ͢Δ͜ͱ Done ✅ • DockerfileΛॻ͍ͯϏϧυ͢Δ·Ͱͷ؆୯ͳྲྀΕΛཧղ͢Δ ͜ͱ Done ✅

    • Dockerʹ͓͚ΔσΟεΫΠϝʔδ؅ཧػೳɾϓϩηε؅ཧ
  31. ਫΛҿΉ࣌ؒ !

  32. Dockerʹ͓͚ΔσΟεΫΠϝʔδ؅ཧ ػೳɾϓϩηε؅ཧ

  33. σΟεΫΠϝʔδ؅ཧػೳ

  34. ͖ͬ͞ɾɾɾ

  35. FROM yukiyan_w/centos:centos6 MAINTAINER Yuki Wakayama RUN yum -y install httpd

    RUN echo 'Hello, World!!' > /var/www/html/index.html ADD init.sh /usr/local/bin/init.sh RUN chmod u+x /usr/local/bin/init.sh CMD ["/usr/local/bin/init.sh"] ↓ docker build -t yukiyan_w/apache:ver1.0 .
  36. FROM yukiyan_w/centos:centos6 DockerfileͰ͸ॻ͍ͯΔ͚ͲɺϏϧυ͸centos7Ͱߦͬͨ

  37. • ίϯςφ಺෦ͰCentOS6͕ήετOS ͱͯ͠ಈ͍ͯΔΘ͚Ͱ͸ͳ͍ • ίϯςφ಺෦Ͱ͸CentOS6ͷ؀ڥͱ ಉ͡σΟεΫͷ಺༰͕ݟ͑Δ • CentOS6ͷσΟεΫʹೖͬͯΔόΠ φϦ/usr/sbin/httpd͔ΒσʔϞϯ ϓϩηεΛىಈ͢Δ

    ήετOSͷىಈϓϩηεΛলུͯ͠ɺ ໨తͷΞϓϦέʔγϣϯ͚ͩ௚઀ىಈ ͢Δ͜ͱ͕Ͱ͖Δ
  38. ͔ͩΒ଎͍

  39. Dockerʹ͓͚ΔσΟεΫΠϝʔδ؅ཧػೳ Doneɾϓϩηε؅ ཧ

  40. ϓϩηε؅ཧ

  41. ෳ਺ཱͯͨίϯςφ͸ɺͦΕͧΕಠཱͨ͠ϓϩηεςʔϒϧ͕ ׂΓ౰ͯΒΕΔ

  42. ͖ͬ͞ݴͬͨ ήετOSͷىಈϓϩηεΛলུͯ͠ɺ໨తͷΞϓϦέʔγϣϯ ͚ͩ௚઀ىಈ͢Δ͜ͱ͕Ͱ͖Δ

  43. ໨తͷΞϓϦέʔγϣϯ FROM yukiyan_w/centos:centos6 MAINTAINER Yuki Wakayama RUN yum -y install

    httpd RUN echo 'Hello, World!!' > /var/www/html/index.html ADD init.sh /usr/local/bin/init.sh RUN chmod u+x /usr/local/bin/init.sh CMD ["/usr/local/bin/init.sh"]
  44. ήετOSͷىಈϓϩηεΛলུͯ͠ɺ໨తͷΞϓϦέʔγϣϯ ͚ͩ௚઀ىಈ͢Δ͜ͱ͕Ͱ͖Δ ↓ ໨తͷΞϓϦέʔγϣϯ͕ PID=1 Ͱىಈ͞ΕͯΔ͸ͣ

  45. docker@dev:~$ docker run -itd -p 8000:80 --name apache01 yukiyan_w/apache:ver1.0 docker@dev:~$

    docker attach apache01 [root@3a607e0dd9f9 /]# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 15:09 ? 00:00:00 /bin/bash /usr/local/bin/init.sh root 17 1 0 15:09 ? 00:00:00 /usr/sbin/httpd root 19 1 0 15:09 ? 00:00:00 /bin/bash apache 20 17 0 15:09 ? 00:00:00 /usr/sbin/httpd apache 21 17 0 15:09 ? 00:00:00 /usr/sbin/httpd apache 22 17 0 15:09 ? 00:00:00 /usr/sbin/httpd root 36 19 0 15:10 ? 00:00:00 ps -ef Dockerfileͷ࠷ऴߦͷίϚϯυ͕PID=1Ͱಈ͍ͯΔʂʂ CMD ["/usr/local/bin/init.sh"]
  46. ϗετOS͔Βݟ͑Δϓϩηε docker@dev:~$ ps -ef UID PID PPID C STIME TTY

    TIME CMD ʙ(Ұ෦লུ)ʙ root 1019 1 0 06:14 ? 00:00:42 /usr/local/bin/docker daemonɹলུ root 9832 1019 0 16:54 ? 00:00:00 docker-proxy -proto tcp লུ root 9844 1019 0 16:54 pts/1 00:00:00 /bin/bash /usr/local/bin/init.sh root 9862 9844 0 16:54 ? 00:00:00 /usr/sbin/httpd root 9864 9844 0 16:54 pts/1 00:00:00 /bin/bash 48 9865 9862 0 16:54 ? 00:00:00 /usr/sbin/httpd 48 9867 9862 0 16:54 ? 00:00:00 /usr/sbin/httpd 48 9868 9862 0 16:54 ? 00:00:00 /usr/sbin/httpd docker 9882 7689 0 16:54 pts/0 00:00:00 ps -ef ίϯςφͰಈ͍ͯΔϓϩηε͸ݟ͑Δ͚ͲɺPID͕ҧ͏ʂʂ
  47. None
  48. Dockerʹ͓͚ΔσΟεΫΠϝʔδ؅ཧػೳ Doneɾϓϩηε؅ ཧ Done

  49. Progress ! • Dockerͷಛ௃ɾར఺Λཧղ͢Δ͜ͱ Done ✅ • DockerfileΛॻ͍ͯϏϧυ͢Δ·Ͱͷ؆୯ͳྲྀΕΛཧղ͢Δ ͜ͱ Done

    ✅ • Dockerʹ͓͚ΔσΟεΫΠϝʔδ؅ཧػೳɾϓϩηε؅ཧ Done ✅
  50. Summary

  51. Summary • Dockerͷಛ௃ɾར఺Λཧղ͢Δ͜ͱ • Vagrant౳ͱൺֱͯ͠ىಈ͕଎͍ɻ • ίϯςφͷ৔߹͸ɺԾ૝Ϛγϯ΍ήετOSͱ͍͏ߟ͑ํ ͸͋Γ·ͤΜɻ • σϓϩΠ͕खܰʹͳΔ

    • εέʔϥϏϦςΟɾߴޮ཰ɾ൚༻ੑ
  52. Summary • DockerfileΛॻ͍ͯϏϧυ͢Δ·Ͱͷ؆୯ͳྲྀΕΛཧղ͢Δ ͜ͱ 1. Dockerfileॻ͘ 2. Ϗϧυ͢Δ 3. docker

    run͢Δ 4. ϨδετϦ΁push
  53. Summary • Dockerʹ͓͚ΔσΟεΫΠϝʔδ؅ཧػೳɾϓϩηε؅ཧ • ήετOSͷىಈϓϩηεΛলུͯ͠ɺ໨తͷΞϓϦέʔ γϣϯ͚ͩ௚઀ىಈ͢Δ͜ͱ͕Ͱ͖Δ • ϗετOS͔Β͸ίϯςφͷϓϩηε͕ݟ͑Δ͚Ͳɺίϯ ςφ͔ΒϗετOSͷϓϩηε͸ݟ͑ͳ͍

  54. Next time... • Ԡ༻తͳ෦෼ • σʔλͷӬଓԽ • ؂ࢹɺϩΪϯά • ωοτϫʔΫ

    • पลٕज़ • swarm, compose • k8s, ECS
  55. Build, Run, Enjoy !

  56. Thanks for listening!