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

Dockerでドカドカ on FuraIT #36

Aruneko
October 07, 2017

Dockerでドカドカ on FuraIT #36

FuraIT #36で発表したDocker勉強会の資料です。
ハンズオンで使用したファイルはこちら
https://github.com/aruneko/furait36_docker

Aruneko

October 07, 2017
Tweet

More Decks by Aruneko

Other Decks in Technology

Transcript

  1. ͱΓ͋͑ͣΠϯετʔϧ w ֤छσΟετϦʹEPDLFSύοέʔδͱͯ͠ొ࿥ࡁΈ ͷ͸ͣ  w ޙͰ࢖͏ͷͰEPDLFSDPNQPTFύοέʔδ΋ಋೖ w 6CVOUVͱ"SDIͱNBD04Ͱͷྫ •

    $ sudo apt install docker docker-compose • $ sudo pacman -S docker docker-compose • $ brew cask install docker
  2. ࣗݾ঺հ w ͋ΔͶ͜ w -0$"-ֶੜ෦લ෦௕ w ࣨའ޻ۀେֶ৘ใઐ߈. w ֶ಺Ͱ4".*5΍ͬͯ·͢ w

    "SDI/FP7JN74$PEF)BTLFMM w ϥϘΫϥ΢υαʔϏε 3FENJOFͳͲ ʹ%PDLFSΛ׆༻த
  3. %PDLFSίϯςφ w ٕज़ͱͯ͠͸ผʹ৽͘͠ͳ͍ DISPPU KBJM TZTUFNEOTQBXOʜFUD  w ಛ௃ͱݴͬͯ΋͜Μͳײ͡ w

    ϓϩηε͕ϗετଆͱ͸ಠཱ w ωοτϫʔΫ΋ಠཱ w DISPPUͱಉ༷ίϯςφ಺ͷΈͷSPPUσΟϨΫτϦ w Ϣʔβʔ΋ಠཱ
  4. ΤίγεςϜͱΠϝʔδ w ๛෋ͳ#BTF*NBHF w 6CVOUV $FOU04 "SDI-JOVY %FCJBO "MQJOF-JOVYʜFUD w

    ෳ਺ͷ*NBHFؒͰ-BZFSΛڞ༗͢Δ͜ͱ͕Մೳ w μ΢ϯϩʔυ༰ྔͷઅ໿ w ࣗ࡞ίϯςφొ࿥࣌ͷΞοϓϩʔυ༰ྔͷઅ໿
  5. ςετ༻ίϯςφͷىಈ • $ docker run -it --rm --name test ubuntu:16.04

    Φϓγϣϯ આ໌ JU UUZΛ࡞ͬͯඪ४ೖྗΛͭͳ͙ SN ίϯςφऴྃ࣌ʹίϯςφΛ࡟আ OBNF ίϯςφʹ໋໊
  6. 4-ͷΠϯετʔϧ w ίϯςφ಺ͰBQUΛ࢖ͬͯTMΛೖΕͯΈΔ w ύοέʔδ໊͕Θ͔Βͳ͍ͱ͖͸BQUͰ୳ͦ͏ w ೖΕऴΘͬͨΒɺIJTUPSZίϚϯυͰ࣮ߦͨ͠ίϚϯυΛ֬ೝ w %PDLFSpMF͸શࣗಈ࣮ߦ w

    ࣮ߦதͷϓϩϯϓτʹೖྗͰ͖ͳ͍ w ڧ੍ΠϯετʔϧΦϓγϣϯͳͲ BQUͷ৔߹Z ͕ඞਢͳͷͰ஫ҙ w ϨΠϠ͕෼ׂ͞ΕΔͱෆ౎߹͕͋ΔͷͰʮʯͰશίϚϯυΛͭͳ͙
  7. %PDLFSpMFͷྫ FROM ubuntu:16.04 RUN apt update && \ apt install

    -y sl && \ ln -s /usr/games/sl /usr/bin/sl
  8. %PDLFSpMF͔ΒΠϝʔδΛ࡞੒ w %PDLFSpMF͕Ͱ͖ͨΒɺ͜ΕΛ࢖ͬͯࣗ࡞ΠϝʔδΛ࡞੒ • $ docker image build -t sl

    . w UɿΠϝʔδ໊Λ෇͚Δ w ࠷ޙͷʮʯɿ%PDLFSpMFͷ͋ΔσΟϨΫτϦ΁ͷ૬ରύε
  9. ࣗ࡞Πϝʔδ͔ΒίϯςφΛੜ੒ • $ docker container run -it -d --name sl_test

    sl w Ұ൪࠷ޙͷҾ਺ʹͰ͖͕͋ͬͨࣗ࡞ΠϝʔδΛࢦఆ w EɿόοΫάϥ΢ϯυ࣮ߦ w ίϯςφऴྃ࣌ʹফ͑ͨΒࠔΔͷͰSN͸ࢦఆ͠ͳ͍
  10. ίϯςφͷ࡟আ w ͍Βͳ͘ͳͬͨίϯςφ͸ࢭΊ͔ͯΒ࡟আ w ಈ͍͍ͯΔίϯςφ͸DPOUBJOFSαϒίϚϯυͷMTίϚϯυͰ֬ೝ w ఀࢭத΋ؚΊ͢΂ͯͷίϯςφΛݟ͍ͨͳΒBΦϓγϣϯ • $ docker

    container ls -a • $ docker ps -a w ίϯςφ*%·ͨ͸ίϯςφ໊Λࢦఆͯ͠࡟আ • $ docker container stop CONTAINER_NAME • $ docker container rm CONTAINER_NAME
  11. Πϝʔδͷ࡟আ w ͍Βͳ͍Πϝʔδ͸༰ྔΛ৯͏͚ͩͳͷͰ࡟আ w Πϝʔδ͸JNBHFαϒίϚϯυͰૢ࡞ w ΠϝʔδͷҰཡ͸MTίϚϯυͰऔಘ • $ docker

    image ls • $ docker images w SNίϚϯυͰ࡟আ • $ docker image rm IMAGE_NAME • $ docker rmi IMAGE_NAME
  12. 4-Ͱ.VMUJ4UBHF#VJMEΛମݧ FROM alpine AS build-sl RUN apk --no-cache add alpine-sdk

    ncurses-dev && \ git clone https://github.com/mtoyoda/sl.git && \ cd sl && \ make FROM alpine RUN apk --no-cache add ncurses COPY --from=build-sl /sl/sl /usr/bin/sl "4ͰதؒΠϝʔδʹ໋໊ GSPNͰதؒΠϝʔδ͔Β੒Ռ෺Λίϐʔ
  13. ΕͬͭԼௐ΂  w 5BH w MBUFTUͰΑͦ͞͏ w ґଘ͍ͯ͠Δίϯςφ w ͳΜΒ͔ͷ%#͕ඞཁΒ͍͠ͱΓ͋͑ͣ.Z42-

    w ࢖͑Δ؀ڥม਺ w %#ͷ઀ଓઌ΍ύεϫʔυ͕ࢦఆग़དྷΔΒ͍͠ w ಺෦Ͱ࢖͏ϙʔτ w ൪ w ӬଓσʔλͷϚ΢ϯτ৔ॴ w lVTSTSDSFENJOFpMFTzʹఴ෇ϑΝΠϧ͕ஔ͔ΕΔΒ͍͠
  14. ΕͬͭԼௐ΂  w 5BH w MBUFTUͰΑͦ͞͏ w ࢖͑Δ؀ڥม਺ w SPPUͷύεϫʔυ΍ॳظ%#໊͕ࢦఆग़དྷΔΒ͍͠

    w ӬଓσʔλͷϚ΢ϯτ৔ॴ w lWBSMJCNZTRMzʹσʔλϕʔε͕ஔ͔ΕΔΒ͍͠
  15. 3FENJOFίϯςφΛ࡞Δ w ίϚϯυ͸ͨͬͨͷߦʢߦ͕୹͍ͱ͸ݴͬͯͳ͍ʣ • $ docker volume create --name redmine_db

    • $ docker volume create --name redmine_file • $ docker run -d --name rm-mysql \
 -e MYSQL_ROOT_PASSWORD=password \
 -e MYSQL_DATABASE=redmine -v redmine_db:/var/lib/mysql mysql • $ docker run -d -p 3000:3000 --name redmine \
 --link rm-mysql:mysql \
 -v redmine_file:/usr/src/redmine/files redmine
  16. 3FENJOFͰͷྫ version: '3' services: mysql: image: mysql volumes: - data:/var/lib/mysql

    environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: redmine redmine: image: redmine volumes: - files:/usr/src/redmine/files ports: - "3000:3000" environment: REDMINE_DB_MYSQL: mysql REDMINE_DB_PASSWORD: password depends_on: - mysql volumes: data: files:
  17. ͍࣮͟ߦ • $ docker-compose up -d w EɿόοΫάϥ΢ϯυ࣮ߦ w ͢΂ͯͷίϯςφΛࢭΊ͍ͨͱ͖

    • $ docker-compose stop w ͢΂ͯͷίϯςφΛఀࢭ͔ͯ͠Β࡟আ͍ͨ͠ͱ͖ • $ docker-compose down
  18. 7PMVNFͷόοΫΞοϓ w όοΫΞοϓ༻ͷҰ࣌ίϯςφΛ࡞ΓϗετଆʹϑΝΠϧΛίϐʔ • $ mkdir bkup && cd bkup

    • $ docker run --rm -v VOL_NAME:/volume \
 -v $(realpath .):/bkp busybox \
 tar cvf /bkp/FILENAME.tar /volume