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

dev-with-docker

ryo nakamaru
September 09, 2016

 dev-with-docker

「M3 tech meetup! #3 ~ Docker について語ろう ~」でお話した LT 資料です。

ryo nakamaru

September 09, 2016
Tweet

More Decks by ryo nakamaru

Other Decks in Technology

Transcript

  1. ຊ൪޲͚͸ͪ͜ΒΛ͝ࢀর͍ͩ͘͞.. 1. AWS ͷίϯςφؔ࿈αʔϏε֓ཁ 2. جຊతͳߏ੒ɾߋ৽ྫ 2.1. ECSɻ 2.2. ElasticBeanstalkɻ

    2.3. CodeDeployɻ 3. AWS ͷϚΠΫϩαʔϏεࢧԉαʔϏε 4. ϑΣʔζผͷߏ੒ྫɾࣄྫ 4.1. ։ൃ؀ڥ 4.2. ධՁ؀ڥ 4.3. ຊ൪؀ڥ 15
  2. ͓࿩͢͠Δ͜ͱ αʔϏεΛ Docker Խ͍ͯ͘͠Ұྫ 1. ΞϓϦέʔγϣϯͷ Docker Խ 1.1. Docker

    Խ͢΂͖͔໰୊ 1.2. Docker Խͷखॱ 1.3. ӡ༻Λҙࣝͨ͠ߏ੒ 1.4. ։ൃΛҙࣝͨ͠ߏ੒ 2. ։ൃ؀ڥͷ Docker Խ 2.1. ӡ༻νʔϜ಺Ͱͷ஌ݟڞ༗ 2.2. ։ൃऀʹ࢖ͬͯ΋Β͓͏ɻ 2.3. Ծ૝؀ڥར༻ύλʔϯ
  3. 1.1 Docker Խ͢΂͖͔໰୊ Dockerɺ͍͍ͱ͸ฉ͚͘Ͳ.. • ΄Μͱ͏ʹ͍͍͔Ͳ͏͔ͳΜͯ࢖ͬͯΈͳ͍ͱΘ͔Βͳ͍ - ؀ڥґଘ͢ΔαʔϏεͷىಈ ‣ ྫʣTensorFlow:

    1. pip install, 2. Virtualenv, 3. source.. ‣ → docker run - -rm -p 80:8888 gcr.io/tensorflow/tensorflow - Dependency hellɻ • ͱ͸͍͑ɺνϡʔτϦΞϧఔ౓Ͱ͸ӡ༻͕૝૾Ͱ͖ͳ͍ • ӡ༻·Ͱͯ͠Έͳ͍ͱϐϯͱ͜ͳ͍ - ·ͣ͸ Web αʔό͔Β.. • ͠͹Β͘ӡ༻͢Ε͹ • ͜ͷΞϓϦ͸ Docker ͷ΄͏͕͍͍͔΋ʂ͕Θ͔Δʢ͔΋ʣ
  4. 1.2 Docker Խͷखॱ ྫʣLAMP • LinuxɺApacheɺMySQLɺPHP ͩͱ͠·͠ΐ͏ • ΰʔϧͷݕ౼ -

    MySQL ͸ެࣜͷ Docker ΠϝʔδΛ࢖͏ - PHP ͷ Docker ΠϝʔδͷϨΠϠʔʢ֊૚ʣΛͲ͏͢Δ͔ ‣ Apache & PHP & ΞϓϦέʔγϣϯ ‣ Apache & PHP > ΞϓϦέʔγϣϯ ‣ Apache > PHP > ΞϓϦέʔγϣϯ ← ࠓճ͸ɺઆ໌্ָͳ͜Εʂ • ྫʣ ubuntu:14.04 my/php:5.6 my/apache:2.4 my/app:1.0
  5. Docker ΠϝʔδͷϨΠϠʔ໰୊ Ͳ͜·ͰΛ && ͰͻͱͭͷϨΠϠʔʹ·ͱΊΔ͔ • Dockerfile ΛΘ͚Δʢ= ϨΠϠʔ͕૿͑Δʣͷ͔·ͱΊΔʢݮΒ͢ʣͷ͔ -

    σϓϩΠͷ଎͞ʢΩϟογϡޮ཰ʣͷҧ͍ - ୹͘෼͚ΔಡΈ΍͔͢͞ɺ1ϑΝΠϧͰಡΊΔҰཡੑ͔ - ੬ऑੑରԠɺϛυϧ΢ΣΞߋ৽ͷ͠΍͢͞ͷҧ͍ - ϓϩδΣΫτɺ෦໳ؒͰԣల։ɾڞ௨Խ͢Δͷ͔ - ͳͲͳͲ.. • ૊৫্ͷ౎߹͕ͳ͍ݶΓϨΠϠʔ͸গͳ͍΄͏͕͍͍ʢ30୅ ձࣾһஉੑʣ - Πϯϑϥ෦໳ͰϕʔεΠϝʔδΛఏڙɺͳͲͱͳΔͱ࢓ํͳ͍ • Dockerfile Λ෼ׂʢdocker ΠϝʔδΛܧঝʣ͢Δ͜ͱ͸
  6. Apache ΠϝʔδΛ࡞Δ ɻ • https://github.com/docker-library/httpd/blob/master/2.4/Dockerfile ɻ • ↑ ͍͖ͳΓެࣜͷ Dockerfile

    ͩͱཁ఺͕Θ͔Γʹ͍͘ - ιʔείϯύΠϧʢݫີͳόʔδϣϯࢦఆʣ ͯ͠Δ - νΣοΫαϜ΍ॺ໊ͷݕূ΋͍ͯ͠Δ - Docker ΠϝʔδΛܰ͘͢Δ֤छ޻෉ • ΋ͬͱγϯϓϧʹ͢Δͱ FROM ubuntu:14.04 RUN apt-get update && apt-get install -y apache2 apache2-threaded-dev RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf CMD ["apachectl", "-D", "FOREGROUND"]
  7. Apache ΠϝʔδΛ࡞Δ ɻ • Docker Πϝʔδͷੜ੒ - docker build -t

    my/apache:2.4 . ɻ • Docker ίϯςφͷىಈ - docker run - -name web -p 80:80 my/apache:2.4 ɻ • Docker ίϯςφͷఀࢭɾഁغ - docker stop web - docker rm web
  8. 1.3 ӡ༻Λҙࣝͨ͠ߏ੒ ຊ൪؀ڥͰ࢖͏ΠϝʔδΛςετલʹ࡞Δ • ։ൃ࣌ʹ͸ιʔεΛϚ΢ϯτ͢ΔܗࣜͰ͋ͬͯ΋ ςετɾධՁ࣌ʹ͸ຊ൪ͱಉ͡ܗࣜʹͦΖ͑Δ • → NFS &

    ιʔείʔυΛ -v ͰϚ΢ϯτ ͢ΔΑΓ΋ ιʔείʔυΛ ADD . ͢Δ΄͏͕Ұ؏ੑΛอͪ΍͍͢ etc • αʔϏεؒͷ࿈ܞ΍ϩάͷग़ྗ΋ධՁ؀ڥͰ֬ೝ
  9. CI ؀ڥͰͷϏϧυɾςετ CircleCIɺJenkins ͳͲ͸ docker ϕʔεͰ • CI ͷલॲཧͰ docker

    build • ςετ͸΋ͪΖΜɺຊ൪Ͱ΋ͦͷΠϝʔδΛ࢖͏ • ςετ͕௨ͬͨΒɺຊ൪༻ʹ docker push / save
  10. ධՁɾຊ൪؀ڥͰͷӡ༻ ϩά΍ϝτϦΫεͷऔಘํ๏Λߟ͓͑ͯ͘ • ϩάɿ2016೥ݱࡏɺdocker ͷϩάυϥΠό͸ͱͯ΋༗༻ - fluentdɻ - awslogs /

    gcplogs ͳͲͳͲ • ϝτϦΫε - ͲͷπʔϧɺSaaS Λ࢖͏ͷ͔ - ͦΕʹ߹Θͤͨߏ੒ύλʔϯͷಋೖ
  11. ධՁɾຊ൪؀ڥͰͷӡ༻ σϓϩΠͷํ๏Λߟ͑Δ • Ϋϥ΢υͷϚωʔδυαʔϏε - Amazon EC2 Container Serviceɻ -

    Google Container Engineɻ - Azure Container Service ͳͲͳͲ • ͜Ε·Ͱ௨ΓͷσϓϩΠπʔϧΛ࢖͏ - docker ΁ରԠ͍ͯ͠ΔͳΒ࠷ߴ - γΣϧ͕ऽΕ͑͢͞Ε͹໰୊ͳ͍
  12. ϑΝΠϧ؂ࢹͱλεΫ࣮ߦ Docker ͷಈ͘ VM ಺ͷϑΝΠϧมߋΛݕ஌ • ։ൃத͸ͦΕΛτϦΨʹԿ͔͍ͨ͜͠ͱ͕ଟʑ͋Δ reload ͱ͔ϦίϯύΠϧͱ͔ •

    inotify ܥͷπʔϧΛಋೖʢΞϓϦͷྡʹίϯςφىಈ etcʣ • VM ΁ͷϚ΢ϯτΦϓγϣϯݕ౼ ೔ຊޠʹͳ͍ͬͯͳ͍༏ྑهࣄ΋ӳޠͳΒ..
  13. VirtualBox + Vagrant Ծ૝ϗετ಺Ͱ Docker Λىಈ • VirtualBox: Ծ૝Խιϑτ΢ΣΞɺVagrant: ߏ੒؅ཧιϑτͷϥούʔ

    • ฐࣾͰ͸ CoreOS Λ಺෦ VM ͱͯ͠ىಈ • ىಈ࣌ʹ૸ΔγΣϧͰॳظԽॲཧ • cloud-config + systemd ·ͨ͸ docker ίϚϯυͰαʔϏεىಈ • ͍ͣΕͷํ๏Ͱ΋ɺΞϓϦ͸ docker ίϯςφͱͯ͠ಈ͘ • VM ʹʢ೚ҙʹʣৼͬͨ IP / ϗετ໊Ͱίϯςφʹ઀ଓͰ͖Δ
  14. VirtualBox + Vagrant ͷಛ௃ ౰ॳΑΓར༻ɺݱࡏ΋ओྲྀ͸ Vagrantʢࣾ಺ͷ࿩ʣ • vagrant-hostsupdater ͷଘࡏ -

    ϓϩδΣΫτ͝ͱʹ઀ଓઌϗετ໊͕΋ͯΔ - ؀ڥར༻ऀ͸ /etc/hosts Λؾʹ͢Δඞཁ͕ͳ͍ • ෳ਺ϓϩδΣΫτΛಉ࣌ىಈ͠΍͍͢ - Ҋ݅ A / Bɺ؀ڥ α / βɺ֎෦ API ϞοΫ.. - ϦϙδτϦ෼ׂ͞ΕͨϚΠΫϩαʔϏεͳͲ΋ରԠՄ • ฐࣾ SIer Ͱ͕͢ɺ͓٬༷΁ͷల։࣌΋Ұ൪༰қ • ࣾ಺ Vagrant ΤΩεύʔτͷଘࡏ Twitter: @toricls ʢຊࢿྉͷଟ͘ͷ஌ݟ special thanks to himʣ ʢͨͩɺ൴͸ Twitter Ͱ Vagrant ͷ͜ͱ͸΄΅ͭͿ΍͖·ͤΜসʣ
  15. Docker Toolbox Docker ͕ࣾఏҊ͢ΔʮVagrant + γΣϧʯͷ୅ସ • 2015/08/12 Ұൠެ։ •

    docker, docker-compose, docker-machine ͕Πϯετʔϧ͞ΕΔ • VirtualBox ΋Πϯετʔϧ͞Εɺdocker-machine ܦ༝Ͱ VM ىಈ • VM ʹৼΒΕͨ IPʢ192.168.99.100ʣͰίϯςφʹ઀ଓͰ͖Δ
  16. Docker Toolbox ͷಛ௃ Docker for Native ҆ఆҎલʹ͸࢖͍ͬͯ·ͨ͠ɻ • docker-compose.yml ͑͞ॻ͚͹ಈ͘ͷ͸ؾ͍͍࣋ͪ

    - Docker for Mac / Windows Ͱ΋ಉ͡ϝϦοτ • docker-machine Λۦ࢖͢Ε͹ɺෳ਺ϓϩδΣΫτ΋ಈ͘ - શһʹ Docker Machine Λशಘͯ͠΋Β͏ͷ͸ίετ͕ߴ͍ - νʔϜͰڞ௨ͷ઀ଓ໊Λ࡞Δͷʹ͸޲͍͍ͯͳͦ͏ • ࠓޙɺDocker for Mac / Windows ΑΓߋ৽͕஗Εͦ͏ - v1.12 ରԠ͞ΕΔ·ͰͷλΠϜϥά͕ා͔ͬͨ • ͍ͭݟࣺͯΒΕΔͷ͔Θ͔Βͳ͍ෆ҆
  17. Docker for Mac / Windows Docker ͕ࣾఏҊ͢Δ࣍ੈ୅ͷϩʔΧϧ؀ڥʂ • 2016/07/28 Ұൠެ։

    • ୤ VirtualBoxɺMac ͱ Windows Ͱ֤ OS ʹ߹Θ࣮ͤͨ૷ • docker-machine (or Toolbox) ͱ΋ཱ྆͢Δ • ങऩ͞Εͨ Unikernel ࣾһ͕ؤுͬͨʁ
  18. খ͞ͳϓϩδΣΫτ͸͜ΕͰे෼ʂ • ͨͩ͠ Mac Λด͡ΔɺεϦʔϓʹೖͬͨ࣌ͷ - containerd ͕෼͔Εͨ݁ՌΆ͍.. - εϦʔϓ͢Δ·͑ʹ౎౓

    docker ऴྃͯ͠Δࢲ.. • ͱ͸͍͑΍͸Γɺখ͞ͳϓϩδΣΫτͰ͸͜Ε͕࠷΋ศརɻ • Toolbox ΑΓ΋৽όʔδϣϯ΁ͷରԠ͸ૣ͍ Docker for Mac / Windows ͷಛ௃
  19. Solomon Hykes Founder & CTO of Docker “ɹɹɹɹɹɹɹɹɹ ” To

    program, you need tools. If these tools are not designed to be accessible and useful to programmers of all levels of expertise and specialization, then as an industry we failed. ɹɹɹɹɹɹɹɹɹ ”