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

Docker Hands-on

Docker Hands-on

社内勉強会用資料です

yubessy

June 19, 2018
Tweet

More Decks by yubessy

Other Decks in Programming

Transcript

  1. Agenda • Part 1. Docker ͷجૅ • Part 2. Dockerfile

    ͷجૅ • Part 3. Docker Compose ͷجૅ
  2. εϥΠυͷίϚϯυ ࣮ࡍʹೖྗͯ͠΋Β͏෦෼͸ $ ·ͨ͸ # ͔Β࢝·Δ $ ... // ϗετͰ࣮ߦ͢ΔίϚϯυ

    # ... // ίϯςφ಺෦Ͱ࣮ߦ͢ΔίϚϯυ ಛʹॏཁͳ෦෼͸ଠࣈʹ͍ͯ͠Δ $ ... # ...
  3. Agenda • Part 1. Docker ͷجૅ • ίϯςφͷىಈɾఀࢭɾഁغ • ίϯςφͷ༷ʑͳىಈΦϓγϣϯ

    • ࣮ߦதͷίϯςφʹର͢Δૢ࡞ • Part 2. Dockerfile ͷجૅ • Part 3. Docker Compose ͷجૅ
  4. ༻ޠ • ίϯςφ • ϓϩηεͱͦͷ࣮ߦ؀ڥ ʢfilesystem, network, etc.ʣ ΛΧϓηϧԽͨ͠΋ͷ •

    ϝΠϯϓϩηε • ίϯςφͷத֩ͱͳΔ୯Ұͷϓϩηε • Πϝʔδ • ίϯςφΛΞʔΧΠϒ͠ɺσʔλͱͯ͠΍ΓͱΓͰ͖ΔΑ͏ʹͨ͠΋ͷ • ϗετ • ίϯςφΛಈ͔ͨ͢ΊͷϚγϯʢ֤ࣗͷ Mac ౳ʣ
  5. Πϝʔδͷμ΢ϯϩʔυ ΠϝʔδΛऔಘ͢Δํ๏͸̎ͭ 1. Web͔Βμ΢ϯϩʔυ͢Δ ← ·ͣ͸ͪ͜Β͔Β 2. ࣗ෼Ͱ࡞Δ ← ͋ͱͰղઆ

    ҎԼͷίϚϯυͰUbuntuͷΠϝʔδΛμ΢ϯϩʔυͰ͖Δ $ docker image pull ubuntu ͜ͷ͋ͱ࢖͏ଞͷΠϝʔδ΋μ΢ϯϩʔυ͓ͯ͘͠ $ docker image pull nginx $ docker image pull python
  6. ίϯςφͷىಈ ࣍ͷίϚϯυͰίϯςφΛىಈͰ͖Δ docker container run <image> <command> ઌఔ pull ͨ͠

    ubuntu Πϝʔδ͔ΒίϯςφΛىಈͯ͠ΈΔ $ docker container run ubuntu echo hello command Ͱىಈͨ͠ϓϩηεʢ͜ͷ৔߹͸ echo hello ʣ͕ϝΠϯϓϩηε ϝΠϯϓϩηεͷੜࢮ = ίϯςφͷىಈɾఀࢭ ͜ͷ৔߹ echo hello ͸͙͢ऴྃ͢ΔͷͰɺίϯςφ͸͙͢ఀࢭ͢Δ
  7. ىಈதίϯςφͷҰཡ ࠓ౓͸ sleep ίϚϯυΛϝΠϯϓϩηεͱͯ͠ίϯςφΛىಈͯ͠ΈΔ $ docker container run ubuntu sleep

    infinity ͜ͷϓϩηε͸ࣗಈͰ͸ऴྃ͠ͳ͍ ଞͷλʔϛφϧͰԼهΛ࣮ߦ͢Δͱɺίϯςφ͕࣮ߦதͰ͋Δ͜ͱ͕Θ͔Δ $ docker container list CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 944883bf35c7 ubuntu "sleep infinity" 3 seconds ago Up 8 seconds nervous_kowalevski
  8. ίϯςφͷఀࢭ IDΛࢦఆͯ͠ઌఔىಈͨ͠ίϯςφΛఀࢭ͢Δ $ docker container stop <container ID> ࠓ౓͸ҰཡʹԿ΋දࣔ͞Εͳͳ͍ $

    docker container list ίϯςφ͸ఀࢭ͕ͨ͠ɺ·ͩഁغ͞Ε͍ͯͳ͍ͷͰ --all Λ͚ͭΔͱݟΕΔ $ docker container list --all STATUS ͕ Exited... ͱͳ͍ͬͯΔ͸ͣ
  9. ίϯςφͷ࠶ىಈ IDΛࢦఆͯ͠ઌఔఀࢭͨ͠ίϯςφΛ࠶ىಈ͢Δ $ docker container start <container ID> ίϯςφ͕࠶ىಈ͞Ε͍ͯΔ͜ͱΛ֬ೝ $

    docker container list ※ϝΠϯϓϩηε͸࠷ॳʹࢦఆͨ͠΋ͷ͔Βม͑ΒΕͳ͍ ΋͏Ұ౓ίϯςφΛఀࢭ͓ͯ͘͠ $ docker container stop <container ID>
  10. ίϯςφͷഁغ IDΛࢦఆͯ͠ઌఔఀࢭͨ͠ίϯςφΛഁغ͢Δ $ docker container rm <container ID> ഁغͨ͠ͷͰ --all

    Λ͚ͭͯ΋ίϯςφ͸ͳ͍ $ docker container list --all ࠶ىಈ΋Ͱ͖ͳ͍ $ docker start <container ID> # Τϥʔ
  11. ͜͜·Ͱͷ͓͞Β͍ docker image pull ΠϝʔδΛμ΢ϯϩʔυ docker container run ίϯςφΛىಈ docker

    container stop|start|rm ίϯςφΛఀࢭ|࠶ىಈ|ഁغ docker container list ίϯςφͷҰཡΛදࣔ ※ࠓճ͸ϑϧίϚϯυΛ༻͍͕ͨɺී௨͸γϣʔτΧοτίϚϯυΛ༻͍Δ docker image pull => docker pull docker container run|stop|start|rm => docker run|stop|start|rm docker container list => docker ps // !!
  12. Agenda • Part 1. Docker ͷجૅ • ίϯςφͷىಈɾఀࢭɾഁغ • ίϯςφͷ༷ʑͳىಈΦϓγϣϯ

    • ࣮ߦதͷίϯςφʹର͢Δૢ࡞ • Part 2. Dockerfile ͷجૅ • Part 3. Docker Compose ͷجૅ
  13. --rm : ఀࢭ࣌ʹଈίϯςφΛഁغ ௨ৗ͸ίϯςφ͕ఀࢭͯ͠΋ഁغ͞ΕΔΘ͚Ͱ͸ͳ͍ $ docker run ubuntu echo hello

    $ docker ps --all // ఀࢭதͷίϯςφ͕ݟ͑Δ ࠶ར༻͠ͳ͍Α͏ͳίϯςφ͸ɺఀࢭޙଈഁغ͢Δ͜ͱ͕Ͱ͖Δ $ docker run --rm ubuntu echo hello $ docker ps --all // ίϯςφ͸ഁغ͞ΕͨͷͰଘࡏ͠ͳ͍
  14. --detach : όοΫάϥ΢ϯυͰىಈ ҎԼͷΑ͏ʹىಈ͢Δͱ docker ίϚϯυࣗମ͸͙͢ऴྃ͢Δ $ docker run --detach

    ubuntu sleep infinity ͔͠͠ίϯςφ͸όοΫάϥ΢ϯυͰಈ͍͍ͯΔ $ docker ps // όοΫάϥ΢ϯυͰ࣮ߦதͷίϯςφ͕ݟ͑Δ όοΫάϥ΢ϯυ࣮ߦதͷίϯςφ͸ऴྃ͢ΔͷΛ๨Εͳ͍Α͏ʹ $ docker stop <container ID>
  15. --interactive --tty : ΩʔϘʔυೖྗΛ༗ޮԽ ҎԼͷΑ͏ʹ͢Δͱɾɾɾ $ docker run --interactive --tty

    ubuntu bash ϓϩϯϓτ͕දࣔ͞ΕɺΩʔϘʔυೖྗΛड͚෇͚Δී௨ͷγΣϧͱͯ͠ಈ࡞ # echo hello // => hello exit ͢ΔͱγΣϧʢίϯςφͷϝΠϯϓϩηεʣ͕ऴྃͯ͠ίϯςφ΋ఀࢭ # exit
  16. --interactive --tty : ΩʔϘʔυೖྗΛ༗ޮԽ ͜ΕΛԠ༻͢Ε͹PythonͳͲͷREPLΛίϯςφ಺Ͱىಈͨ͠Γ΋Ͱ͖Δ $ docker run --interactive --tty

    python python ͦΕͧΕͷΦϓγϣϯͷҙຯ • --interactive : ίϯςφͷඪ४ೖྗΛ։͍͓ͯ͘ • --tty : ίϯςφͷඪ४ೖྗʹλʔϛφϧʢΩʔϘʔυೖྗʣΛ઀ଓ͢Δ ͜ͷ̎ͭͷΦϓγϣϯΛলུͯ͠ -it ͱࢦఆ͢Δ͜ͱ͕ଟ͍ $ docker run -it ubuntu bash
  17. --env : ؀ڥม਺Λઃఆ ίϯςφ಺Ͱࢀর͢Δ؀ڥม਺Λઃఆ $ docker run -it --env HOGE=fuga

    ubuntu bash # echo $HOGE // => fuga ϑΝΠϧ͔ΒಡΈࠐΉ͜ͱ΋Մೳ $ docker run -it --env-file vars.env ubuntu bash vars.env ͷྫ : HOGE=fuga PIYO=poyo
  18. --volume : ϗετͱίϯςφͷσΟϨΫτϦΛಉظ ·ͣ͸ϗετʹద౰ͳσΟϨΫτϦͱϑΝΠϧΛ࡞੒ $ mkdir data && echo hello

    > data/hello.txt ࡞੒ͨ͠σΟϨΫτϦΛίϯςφ಺ͷσΟϨΫτϦͱಉظ͢Δ $ docker run -it --volume $PWD/data:/tmp/data ubuntu bash ίϯςφͷதͰಉظͨ͠ϑΝΠϧΛಡΈॻ͖Ͱ͖Δ # ls /tmp/data // => hello.txt ͕ݟ͑Δ # echo bye > /tmp/data/hello.txt // => hello.txt ʹॻ͖ࠐΊΓ
  19. --publish : ϗετͷϙʔτΛίϯςφʹ઀ଓ ҎԼΛ࣮ߦͯ͠ϒϥ΢βͰ http://localhost:8080/ ʹΞΫηε͢Δͱɾɾɾ $ docker run --publish

    8080:80 nginx nginx -g 'daemon off;' Welcome to nginx! λʔϛφϧʹ໭Δͱඪ४ग़ྗʹϩά͕ग़͍ͯΔ 172.17.0.1 - - [03/Apr/2018:11:23:37 +0000] "GET / ..." ... MySQL΍Rails΋ಉ͡Α͏ʹϙʔτΛ઀ଓͯ͠ىಈͰ͖Δ
  20. σϑΥϧτίϚϯυΛ࣮ߦ ௨ৗ͸ docker run <image> <command> ͱͯ͠ίϚϯυΛ࣮ߦ͢Δ $ docker run

    -it python python ͜ͷ <command> Λলུ͢ΔͱΠϝʔδͷσϑΥϧτίϚϯυ͕࣮ߦ͞ΕΔ $ docker run -it python // PythonͷREPL͕ىಈ Πϝʔδʹ͸͍͍ͨͯԿΒ͔ͷσϑΥϧτίϚϯυ͕ઃఆ͞Ε͍ͯΔ $ docker run -it ubuntu // => bash ͕ىಈ $ docker run --publish 8080:80 nginx // => nginx ͕ىಈ
  21. ͜͜·Ͱͷ͓͞Β͍ • docker run ͷΦϓγϣϯͰίϯςφͷىಈํ๏Λม͑ΒΕΔ • docker run <image> ͰσϑΥϧτίϚϯυΛ࣮ߦͰ͖Δ

    ओཁͳΦϓγϣϯʹ͸লུܗ͕༻ҙ͞Ε͍ͯΔ ( docker run --help Ͱ֬ೝͰ͖Δ) --detach => -d --env => -e --interactive => -i --volume => -v --tty => -t --publish => -p
  22. Agenda • Part 1. Docker ͷجૅ • ίϯςφͷىಈɾఀࢭɾഁغ • ίϯςφͷ༷ʑͳىಈΦϓγϣϯ

    • ࣮ߦதͷίϯςφʹର͢Δૢ࡞ • Part 2. Dockerfile ͷجૅ • Part 3. Docker Compose ͷجૅ
  23. ϗετͱίϯςφͷؒͰϑΝΠϧΛίϐʔ ίϯςφΛىಈ $ docker run -it ubuntu ϗετͰద౰ʹϑΝΠϧΛ࡞੒͠ɺίϯςφͷதʹίϐʔ $ echo

    hello > test.txt $ docker container cp test.txt <container ID>:/tmp ίϯςφͷதͰϑΝΠϧΛ֬ೝͯ͠ΈΔ # ls /tmp // => test.txt ͕͋Δ͸ͣ
  24. ϝΠϯϓϩηεͷग़ྗΛऔಘ ίϯςφΛόοΫάϥ΢ϯυͰىಈ $ docker run -d -p 8080:80 nginx ϒϥ΢βͰ

    http://localhost:8080/ ʹΞΫηεͯ͠ϩάΛ࢒͢ ίϯςφͷඪ४ग़ྗɾඪ४Τϥʔग़ྗʹه࿥͞ΕͨϩάΛ֬ೝ $ docker container logs <container ID> 172.17.0.1 - - [03/Apr/2018:11:23:37 +0000] "GET / ..." ...
  25. ͓͞Β͍ docker container exec ίϯςφ಺ͰผίϚϯυΛ࣮ߦ docker container cp ίϯςφͱϗετͷؒͰϑΝΠϧΛίϐʔ docker

    container logs ϝΠϯϓϩηεͷग़ྗΛऔಘ ΋ͪΖΜγϣʔτΧοτίϚϯυ΋࢖͑Δ docker container exec => docker exec docker container cp => docker cp docker container logs => docker logs
  26. Agenda • Part 1. Docker ͷجૅ • Part 2. Dockerfile

    ͷجૅ • ΠϝʔδͷϏϧυ • ओͳ໋ྩ • Dockerfile ͷϙΠϯτ • Part 3. Docker Compose ͷجૅ
  27. ༻ޠ • Ϗϧυίϯςφ • ϏϧυதʹҰ࣌తʹ࡞੒͞ΕΔίϯςφ • ϏϧυσΟϨΫτϦ • ϗετͰΠϝʔδͷϏϧυ࡞ۀΛߦ͏σΟϨΫτϦ (Dockerfile

    ͳͲΛஔ͘) • ϫʔΩϯάσΟϨΫτϦ • Ϗϧυίϯςφ಺ͷΧϨϯτσΟϨΫτϦ • ϏϧυΩϟογϡ • Ϗϧυ్தͰΠϝʔδͷ಺༰ΛΩϟογϡͨ͠΋ͷ
  28. Πϝʔδͷऔಘํ๏ ΠϝʔδΛऔಘ͢Δํ๏͸̎ͭ 1. Web͔Βμ΢ϯϩʔυ͢Δ ← Part 1. Ͱ঺հ 2. ࣗ෼Ͱ࡞Δ

    ← ࠓ౓͸ͪ͜Β ࣗ෼Ͱ࡞Δ৔߹Ͱ΋ɺී௨͸طଘͷΠϝʔδΛϕʔεʹΧελϚΠζ͢Δ ͜Ε͔Β࢖͏αϯϓϧΛμ΢ϯϩʔυ͓ͯ͘͠ $ git clone [email protected]:yubessy/docker-handson-example.git $ cd docker-handson-example
  29. Dockerfile Πϝʔδͷ࡞੒खॱΛهड़͢ΔϑΝΠϧʢݟͨ͜ͱ͕͋Δ͸ͣʣ FROM python:3.6 RUN groupadd appgroup && \ useradd

    --system --group appgroup appuser && \ mkdir /opt/myapp && \ chgrp -R appgroup /opt/myapp && \ chown -R appuser /opt/myapp && \ pip install flask COPY --chown=appuser:appgroup main.py /opt/myapp/main.py USER appuser WORKDIR /opt/myapp CMD ["python", "main.py"]
  30. ΠϝʔδͷϏϧυ ҎԼͷίϚϯυͰ Dockerfile ͔ΒΠϝʔδΛϏϧυͰ͖Δ $ docker image build --tag myapp:v0.0.1

    . --tag <name>:<tag>: Ϗϧυͨ͠Πϝʔδʹ໊લͱλάΛ෇༩] .: ϏϧυσΟϨΫτϦͷύε ίϚϯυͱΦϓγϣϯ͸লུՄೳ $ docker build -t myapp:v0.0.1 .
  31. Agenda • Part 1. Docker ͷجૅ • Part 2. Dockerfile

    ͷجૅ • ΠϝʔδͷϏϧυ • Dockerfile ͷओͳ໋ྩ • Dockerfile ͷϙΠϯτ • Part 3. Docker Compose ͷجૅ
  32. RUN : ίϚϯυΛ࣮ߦ ͜ΕΛ࢖ͬͯϕʔεΠϝʔδΛΧελϚΠζ͍ͯ͘͠ && ΍ || ͳͲɺγΣϧεΫϦϓτͱಉ͡ه๏͕࢖͑Δ ྫ: apt-get

    Ͱ mysqlclient ΛΠϯετʔϧ RUN apt-get update && \ apt-get install -y mysqlclient ໋ྩ్தͷվߦ͸ \ Ͱ
  33. COPY : ϑΝΠϧΛΠϝʔδʹؚΊΔ ϏϧυσΟϨΫτϦҎԼͷ೚ҙͷϑΝΠϧΛΠϝʔδʹؚΊΔ COPY example.txt /tmp/example.txt . ΍ *

    ͷΑ͏ͳύλʔϯ΋࢖͑Δ COPY . . --chown ͰϑΝΠϧͷΦʔφʔΛมߋ͢Δ͜ͱ΋Ͱ͖Δ COPY --chown=appuser:appgroup main.py /opt/myapp/main.py
  34. USER , WORKDIR : Ϣʔβ΍σΟϨΫτϦΛ੾Γସ͑ ίϯςφ಺ͷ࣮ߦϢʔβ΍ϫʔΩϯάσΟϨΫτϦΛ੾Γସ͑Δ RUN echo `whoami`:`pwd` #

    root:/ USER appuser WORKDIR /tmp RUN echo `whoami`:`pwd` # appuser:/tmp RUN ͚ͩͰͳ͘ COPY ΍ CMD ͷ࣮ߦϢʔβ΋มΘΔ Ϗϧυதʹ RUN Ͱ cd ΍ su ͸࢖͑ͳ͍͜ͱʹ஫ҙʂ
  35. CMD : σϑΥϧτίϚϯυΛઃఆ docker run <image> Ͱ࣮ߦ͞ΕΔίϚϯυΛࢦఆ ["cmd", "arg1", "arg2"]

    ͷΑ͏ͳه๏Λਪ঑ FROM ubuntu:latest # ௨ৗ͸ bash ͕ىಈ͢Δ͕ɺͦΕΛ্ॻ͖Ͱ͖Δ CMD ["echo", "hello"]
  36. Agenda • Part 1. Docker ͷجૅ • Part 2. Dockerfile

    ͷجૅ • ΠϝʔδͷϏϧυ • Dockerfile ͷओͳ໋ྩ • Dockerfile ͷϙΠϯτ • Part 3. Docker Compose ͷجૅ
  37. ͻͱͭͷ RUN ΍ COPY ʹෳ਺ίϚϯυΛ·ͱΊΔ ໋ྩΛ࣮̍ͭߦ͢ΔຖʹϏϧυΩϟογϡ͕ੜ੒͞Ε͍ͯΔ → ໋ྩΛࡉ͔͘෼͚ΔͱແବʹϏϧυΩϟογϡ͕ੜ੒͞ΕΔ → Ϗϧυ͕஗͘ͳΔɾσΟεΫΛѹഭ͢Δ

    # ྑ͘ͳ͍ྫ RUN groupadd appgroup RUN useradd --system --group appgroup appuser RUN mkdir /opt/myapp RUN chgrp -R appgroup /opt/myapp RUN chown -R appuser /opt/myapp
  38. ඞཁͳϑΝΠϧ͚ͩΛ COPY ͢Δ COPY . . ͳͲͰෳ਺ͷϑΝΠϧΛ·ͱΊͯίϐʔ͢Δͱ͖͸ ҎԼͷΑ͏ͳίϐʔ͢Δͱ໰୊͕͋ΔϑΝΠϧʹؾΛ͚ͭΔ • log/

    : ։ൃதʹੜ੒͞Εͨͨ͘͞Μͷϩά • .env : DBύεϫʔυͳͲ͕ॻ͔Εͨ؀ڥઃఆ ͜ΕΒΛΠϝʔδʹؚΊͳ͍Α͏ .dockerignore Λॻ͍͓ͯ͘ log/ .env
  39. ΞϓϦέʔγϣϯ࣮ߦ༻ͷϢʔβΛ༻ҙ͢Δ ྫͰ͸ΞϓϦέʔγϣϯ࣮ߦઐ༻ͷϢʔβΛΘ͟Θ͟࡞͍ͬͯͨ FROM python:3.6 RUN groupadd appgroup && \ useradd

    --system --group appgroup appuser # ... USER appuser ͜Ε͕ͳ͍ͱ root Ͱϓϩηε͕࣮ߦ͞Ε༧ظͤ͵໰୊͕ൃੜ͢Δ͜ͱ΋
  40. Agenda • Part 1. Docker ͷجૅ • Part 2. Dockerfile

    ͷجૅ • Part 3. Docker Compose ͷجૅ • Docker Compose ͱ͸ • αʔϏεͱωοτϫʔΫ • Docker Compose ͷϕετϓϥΫςΟε
  41. Docker Compose ͱ͸ લճ·Ͱ: • Part 1: ୯Ұͷίϯςφͷૢ࡞ • Part

    2: Πϝʔδͷ࡞੒ ࠓճ: • Part 3: ෳ਺ͷίϯςφͷૢ࡞
  42. docker-compose.yml ͷجຊ docker-compose.yml ʹෳ਺ͷίϯςφΛ·ͱΊͯఆٛ͢Δ version: '3' # ϑΝΠϧϑΥʔϚοτͷόʔδϣϯ services: app:

    build: ./app ports: - 3000:3000 depends_on: - db # ίϯςφͷىಈॱΛDBίϯςφΑΓޙʹ͢Δ db: image: mysql environment: MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
  43. docker-compose ίϚϯυͷجຊ docker-compose.yml ͷఆٛΛݩʹίϯςφ΍ΠϝʔδΛૢ࡞͢Δ • docker-compose up: ίϯςφΛ·ͱΊͯىಈ • docker-compose

    down: ίϯςφΛ·ͱΊͯऴྃɾ࡟আ • docker-compose run: ಛఆͷίϯςφΛ୯ҰͰىಈ • docker-compose exec: ىಈதͷίϯςφ಺ͰίϚϯυΛ࣮ߦ • docker-compose pull: ΠϝʔδΛ·ͱΊͯऔಘ • docker-compose build: ΠϝʔδΛ·ͱΊͯϏϧυ ଞʹ΋ͨ͘͞Μ͋ΔͷͰ docker-compose --help Ͱ֬ೝ͓ͯ͘͠
  44. Agenda • Part 1. Docker ͷجૅ • Part 2. Dockerfile

    ͷجૅ • Part 3. Docker Compose ͷجૅ • Docker Compose ͱ͸ • αʔϏεͱωοτϫʔΫ • Docker Compose ͷϕετϓϥΫςΟε
  45. αʔϏεͷओͳઃఆ docker build|run|pull ͳͲͷίϚϯυͷҾ਺ͱରԠ͢Δ΋ͷ build: # docker build <path> <-

    path image: # docker pull|run <image> <- image command: # docker run <image> <command> <- command environment: # docker run --env env_file: # docker run --env-file ports: # docker run --publish volumes: # docker run --volume stdin_open: # docker run --interactive tty: # docker run --tty
  46. ߴ౓ͳωοτϫʔΫͷઃఆ αʔϏεΛෳ਺ͷωοτϫʔΫʹ഑ஔ͢Δ͜ͱ΋Մೳ (։ൃ؀ڥ༻్Ͱ͸΄΅࢖༻͠ͳ͍) version: "3" services: proxy: build: ./proxy networks:

    [frontend] app: build: ./app networks: [frontend, backend] db: image: mysql networks: [backend] networks: frontend: {} backend: {}
  47. Agenda • Part 1. Docker ͷجૅ • Part 2. Dockerfile

    ͷجૅ • Part 3. Docker Compose ͷجૅ • Docker Compose ͱ͸ • αʔϏεͱωοτϫʔΫ • Docker Compose ͷϕετϓϥΫςΟε
  48. Git Submodule ͱ૊Έ߹ΘͤΔ ෳ਺ϨϙδτϦߏ੒ͷ؀ڥΛ up ҰൃͰ্ཱͪ͛ΒΕΔΑ͏ʹ . !"" docker-compose.yml !""

    db # DBॳظԽॲཧͳͲ !"" frontend # ϑϩϯτ (Node.js) ͷ git repo !"" webapp # WebΞϓϦ (Rails) ͷ git repo #"" batchjob # όονॲཧ (Python) ͷ git repo
  49. YAML ͷΞϯΧʔɾΤΠϦΞεΛར༻͢Δ docker-compose.yml ͷ x- ͔Β࢝·Δ߲໨͸ࣗ༝ʹར༻Ͱ͖Δ ͜ΕͱYAMLͷΞϯΧʔ/ΤΠϦΞεΛ૊Έ߹ΘͤΔͱศར version: '3.4' x-db-env-files:

    &db-env-files # ΤΠϦΞε - ./env/db.env - ./env/db.secret services: webapp: ... env_file: *db-env-files # ΞϯΧʔ batchjob: ... env_file: *db-env-files # ΞϯΧʔ