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

Docker3兄弟

Tsuyoshi Torii
August 22, 2015
6.8k

 Docker3兄弟

Docker machine / Docker compose / Docker swarm の話をしました

Tsuyoshi Torii

August 22, 2015
Tweet

Transcript

  1. ΞδΣϯμ w %PDLFSܑ̏ఋͱ͸ʁ w %PDLFSܑ̏ఋͷ͸͡Ί͔ͨ w %PDLFSܑ̏ఋͷ͝঺հ w Ϣʔεέʔε w

    %PDLFSܑ̏ఋΛศརʹ࢖͏ w %PDLFSܑ̏ఋͷ͜Ε͔Β w ·ͱΊ w ͓·͚ɿ%PDLFS$PNQPTFΞοϓσʔτ
  2. 4VQQPSU%SJWFST w "NB[PO8FC4FSWJDFT w .JDSPTPGU"[VSF w %JHJUBM0DFBO w &YPTDBMF w

    (PPHMF$PNQVUF&OHJOF w (FOFSJD w .JDSPTPGU)ZQFS7 IUUQTEPDTEPDLFSDPNNBDIJOFESJWFST w 0QFO4UBDL w 3BDLTQBDF w *#.4PGUMBZFS w 0SBDMF7JSUVBM#PY w 7.XBSFW$MPVE"JS w 7.XBSF'VTJPO w 7.XBSFW4QIFSF
  3. %PDLFS.BDIJOF2VJDL4UBSU # ৽ن࡞੒ docker-machine create … # Ϛγϯ੾Γସ͑ʗදࣔͳͲ docker-machine env

    <name> docker-machine ls # VMૢ࡞ܥ docker-machine start <name> docker-machine stop <name> docker-machine restart <name> # ssh / scp docker-machine ssh <name> docker-machine scp <src> <dest> # VM࡟আ docker-machine rm <name>
  4. MT % docker-machine ls NAME ACTIVE DRIVER STATE URL default

    virtualbox Running tcp://xxx:2376 ec2vm amazonec2 Running tcp://xxx:2376 dovm * digitalocian Running tcp://xxx:2376
  5. %PDLFS$PNQPTF2VJDL4UBSU # ίϯςφىಈ docker-compose up … # ίϯςφεέʔϧ docker-compose scale

    <name>=<num> # େମDockerίϚϯυͱҰॹ docker-compose ps docker-compose build docker-compose pull docker-compose logs docker-compose run docker-compose start docker-compose stop docker-compose restart docker-compose kill docker-compose rm
  6. 4BNQMF:".- webapp: build: . ports: - "5000:5000" volumes: - .:/code

    links: - redis redis: image: redis ΄ͱΜͲͷ%PDLFSΦϓγϣϯʹରԠ͍ͯ͠Δ
  7. :".-ิ଍ webapp: build: ./webapp environment: - DEBUG=false - SEND_EMAILS=false web:

    extends: file: common.yml service: webapp ports: - "8000:8000" links: - db environment: - DEBUG=true db: image: postgres • extends • ֎෦ͷdocker-compose.ymlΛར༻͢Δ͜ͱ͕Ͱ͖Δ DPNNPOZNM EPDLFSDPNQPTFZNM
  8. %JTDPWFSZ w ͍͔ͭ͘ͷσΟεΧόϦɾόοΫΤϯυͱ࿈ܞ w )PTUFE%JTDPWFSZXJUI%PDLFS)VC w Ϋϥελ৘ใ͕هड़͞Εͨ੩తϑΝΠϧ w FUDE w

    DPOTVM w [PPLFFQFS w *1ΞυϨεϦετࢦఆ w *1ΞυϨεൣғࢦఆ IUUQTEPDTEPDLFSDPNTXBSNEJTDPWFSZ
  9. 'JMUFST w εέδϡʔϦϯάͷͨΊͷ͍͔ͭ͘ͷϑΟϧλΛఏڙ͍ͯ͠Δ w $POTUSBJOUϑΟϧλ w "⒏OJUZϑΟϧλ w ஥ྑ͠άϧʔϓʹΑΔϑΟϧλʢίϯςφʗΠϝʔδʗϥ ϕϧʣ

    w 1PSUϑΟϧλ w %FQFOEFODZϑΟϧλ w ಉҰϊʔυ্ͰͷґଘΛεέδϡʔϦϯάʢWPMVNFTGSPN ʗMJOLʗOFUʣ w )FBMUIϑΟϧλ IUUQTEPDTEPDLFSDPNTXBSNTDIFEVMFSpMUFS
  10. 4USBUFHJFT w 4XBSN͸͍͔ͭ͘ͷεέδϡʔϦϯάํ਑Λ͍࣋ͬͯΔ w TQSFBE EFGBVMU  w Ͱ͖Δ͚ͩ෼ࢄ͢Δ w

    CJOQBDL w Ͱ͖Δ͚ͩू໿͢Δ w SBNEPN w ϥϯμϜ IUUQTEPDTEPDLFSDPNTXBSNTDIFEVMFSTUSBUFHZ
  11. τʔΫϯੜ੒ʗ7.ىಈ # create token docker run --rm swarm create #

    create vm # master docker-machine create -d … \ --swarm --swarm-discovery token://$SWARM_TOKEN \ --swarm-master \ vm-swarm-master # node docker-machine create -d … \ --swarm --swarm-discovery token://$SWARM_TOKEN \ vm-swarm-nodex # env ઃఆ eval "$(docker-machine env --swarm vm-swarm-master)"
  12. EPDLFSDPNQPTFZNM web: image: toritori0318/ubuntu-perl-dancer-demoapp ports: - "5000" environment: - REDIS_HOST

    redis: image: redis ports: - "6379:6379" environment: - constraint:node==vm-swarm-master ˞ݱ࣌఺͸MJOL͕ͦͷ··࢖͑ͳ͍ʜ
  13. %BODFS"QQ package MyWeb::App; use Dancer2; use Redis; our $VERSION =

    '0.1'; my $redis_host = $ENV{REDIS_HOST} || 'localhost'; my $redis_port = $ENV{REDIS_PORT} || '6379'; my $redis = Redis->new(server => "${redis_host}:${redis_port}"); get '/' => sub { $redis->incr('hits'); return sprintf("Hello Dancer! I have been seen %s times.", $redis->get('hits')); }; true;
  14. ̍ɽ։ൃ؀ڥ഑෍ w ։ൃऀ͸ɺϦϙδτϦΛ$MPOF͢Δ͚ͩͰΞϓϦέʔγϣ ϯΛ։ൃ͢Δ؀ڥΛߏஙͰ͖Δ w EPDLFSNBDIJOF EPDLFSDPNQPTF w खॱ w

    ʢલఏʣΞϓϦέʔγϣϯϦϙδτϦʹEPDLFS DPNQPTFZNM ЋΛؚΊ͓ͯ͘ w ར༻ऀ͸ϦϙδτϦΛDMPOFͯ͠EPDLFSDPNQPTFVQ w αʔόىಈ΍Ϣχοτςετ͕ͦͷ··ಈ͘
  15. ̎ɽ$*؀ڥ w EPDLFSDPNQPTF؀ڥΛͦͷ··$*Ͱಈ࡞ʗςετΛߦ͏ w EPDLFSDPNQPTF w खॱ w ʢલఏ৚݅ʣέʔε̍ͷ؀ڥΛ༻ҙ͓ͯ͘͠ w

    $*ͷதͰҎԼͷ༷ͳίϚϯυΛ࣮ߦ͢Δ w EPDLFSDPNQPTFCVJMEʜVQʜSVONBLFUFTUʜ w 3FG%SPOF pHͰ$*ςετͯ͠ΈΔ w IUUQRJJUBDPNUPSJUPSJJUFNT GDEBEE
  16. 4XBSN$MVTUFS "[VSF ($& "84 4XBSN .BTUFS 4XBSN/PEF $POUBJOFS 4XBSN/PEF $POUBJOFS

    4XBSN/PEF $POUBJOFS DMJFOU $POUBJOFS $POUBJOFS $POUBJOFS 4XBSN .BTUFS 4XBSN .BTUFS
  17. "MJBT # docker-machine cli alias dm="docker-machine" dme() { command docker-machine

    $1 ${DOCKER_MACHINE_NAME};} # RPrompt get_docker_machine_name() { if [ "$DOCKER_MACHINE_NAME" != "" ]; then echo "(dm=$DOCKER_MACHINE_NAME)" else echo "" fi } RPROMPT=‘%{$fg[green]%}$(get_docker_machine_name)$ \ (git_prompt_info)%{$reset_color%}% '
  18. "MJBT # fig sudo ln -s /usr/loca/bin/docker-compose \ /usr/local/bin/fig #

    fig recreate fig-recreate() { command \ fig stop -t 1 && fig rm —force \ && fig build && fig up -d; }
  19. QFDP # docker-machine env function peco-docker-machine-change() { # docker-machine ls

    + eval local dm_name=$(docker-machine ls | awk '{print $1}' | grep -vw 'NAME' | peco --query "$LBUFFER") if [ -n "$dm_name" ]; then eval "$(docker-machine env ${dm_name})" fi zle reset-prompt } zle -N peco-docker-machine-change bindkey '^x^m' peco-docker-machine-change # docker-machine ssh function peco-docker-machine-ssh() { BUFFER="docker-machine ls | awk '{print \$1}' | grep -vw 'NAME' | peco | awk '{print \$1}' | xargs -o -n 1 docker-mac hine ssh" zle accept-line } zle -N peco-docker-machine-ssh bindkey '^x^s' peco-docker-machine-ssh
  20. [FNCVUTV͞Μ w %PDLFSʗ)BTIJDPSQͳͲͷ৘ใ΍຋༁Λެ։͞Ε͍ͯΔ w %PDLFS.BDIJOFυΩϡϝϯτࢀߟ೔ຊޠ༁ w IUUQRJJUBDPN[FNCVUTVJUFNTEEBEDB w %PDLFS$PNQPTFυΩϡϝϯτࢀߟ೔ຊޠ༁ɾ໨࣍ w

    IUUQRJJUBDPN[FNCVUTVJUFNTDDEBCB w %PDLFS4XBSNυΩϡϝϯτࢀߟ೔ຊޠ༁ɾ໨࣍ w IUUQRJJUBDPN[FNCVUTVJUFNTBGBEEFF
  21. %PDLFS$PNQPTF3PBENBQ include: # link using http servicea: http: http://localhost:8080/projects/servicea/fig.yml #

    local paths serviceb: path: ../projects/serviceb/fig.yml webapp: #... links: - servicea_webapp - serviceb_webapp w ෳ਺νʔϜ࿈ܞΛߟྀ
  22. ·ͱΊ w %PDLFSܑ̏ఋΛ࢖͏ͱ%PDLFSΛΏΔ;Θʹར༻͢Δ͜ͱ͕Ͱ͖Δ w ౷Ұ͞ΕͨΠϯλϑΣʔεʗϙʔλϒϧʗॊೈ w ։ൃ؀ڥͱͯ͠ͷར༻ w े෼ར༻Մೳ w

    ຊ൪؀ڥͱͯ͠ͷར༻ w ·ͩ·ͩ՝୊͸ଟ͍͕ɺ͖ͪΜͱϩʔυϚοϓ͕ఏࣔ͞Ε͍ͯΔ w %PDLFSܑ̏ఋʹ͸ɺເ͕͋Δοʂʂʂ
  23. ·ͱΊ w %PDLFSܑ̏ఋΛ࢖͏ͱ%PDLFSΛΏΔ;Θʹར༻͢Δ͜ͱ͕Ͱ͖Δ w ౷Ұ͞ΕͨΠϯλϑΣʔεʗϙʔλϒϧʗॊೈ w ։ൃ؀ڥͱͯ͠ͷར༻ w े෼ར༻Մೳ w

    ຊ൪؀ڥͱͯ͠ͷར༻ w ·ͩ·ͩ՝୊͸ଟ͍͕ɺ͖ͪΜͱϩʔυϚοϓ͕ఏࣔ͞Ε͍ͯΔ w %PDLFSܑ̏ఋʹ͸ɺເ͕͋Δοʂʂʂ ܑ̐ఋ
  24. ͓·͚ɿ%PDLFS$PNQPTFิ଍ w Ͱ࣮૷͞ΕͨػೳʢҰ෦ʣ w EPDLFSDPNQPTFVQͷվળ w EPDLFSDPNQPTFTUPQLJMMSNTDBMF͕ฒྻ࣮ߦ͢ΔΑ͏ʹͳͬͨ w DPOUBJOFS@OBNFͰίϯςφ໊ΛΧελϚΠζͰ͖ΔΑ͏ʹͳͬͨ w

    αʔϏε໊ʹʮʯʮʯʮ@ʯΛؚΊΕΒΕΔΑ͏ʹͳͬͨ w MPH@ESJWFSͰ೚ҙͷϩάυϥΠόΛར༻Ͱ͖ΔΑ͏ʹͳͬͨ w ඪ४ೖྗ͔Βߏ੒ΛಈతߏஙͰ͖ΔΑ͏ʹͳͬͨ w FDIPSFEJT\JNBHFSFEJT^cEPDLFSDPNQPTFpMFVQ