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

昔の自分に伝えたい容量回復のためのDockerの仕組み / docker_tips

1741ebf45ce415e49fb0340da9e1ca15?s=47 KSK
July 27, 2018

昔の自分に伝えたい容量回復のためのDockerの仕組み / docker_tips

1741ebf45ce415e49fb0340da9e1ca15?s=128

KSK

July 27, 2018
Tweet

More Decks by KSK

Other Decks in Programming

Transcript

  1. ੲͷࣗ෼ʹ఻͍͑ͨ ༰ྔճ෮ͷͨΊͷ Docker ͷ࢓૊Έ ksk1030 @Repro Tech Meetup #1 /

    2018.07.27
  2. ࠓ೔ͷ·ͱΊ

  3. ɹimage → ϓϩάϥϜ ɹcontainer → ϓϩηε ɹvolume → ετϨʔδ ɹ˞ࣗ෼ͳΓʹཧղΛਐΊΔͨΊͷࡶͳ੔ཧͰ͢…

  4. Dockerͱͷग़ձ͍

  5. DockerΛ࢖͍࢝Ίͨ͜Ζ ୭͔͕docker-compose.ymlʹ ͓·͡ͳ͍Λॻ͍ͯ͘Εͨʂ Ͱ΋࢖ͬͯΔͱͲΜͲΜ ༰ྔ৯͏Μ͚ͩͲ…ʁ Α͘Θ͔ΒΜ͚Ͳศརʂ ؀ڥߏஙḿΔʂ

  6. DockerΛ࢖͍࢝Ίͨ͜Ζ ୭͔͕docker-compose.ymlʹ ͓·͡ͳ͍Λॻ͍ͯ͘Εͨʂ Ͱ΋࢖ͬͯΔͱͲΜͲΜ ༰ྔ৯͏Μ͚ͩͲ…ʁ Α͘Θ͔ΒΜ͚Ͳศརʂ ؀ڥߏஙḿΔʂ Կ͕ى͖͍͔ͯͨ ɾ్த͔ΒJoinͨ͠ϓϩδΣΫτͰDocker͕ ɹ࢖ΘΕ͍ͯͨ

    ɾͱΓ͋͑ͣ docker-compose up ɾͦͯ͠ѹഭ͞ΕΔετϨʔδ…
  7. DockerΛ࢖͍࢝Ίͨ͜Ζ ୭͔͕docker-compose.ymlʹ ͓·͡ͳ͍Λॻ͍ͯ͘Εͨʂ Ͱ΋࢖ͬͯΔͱͲΜͲΜ ༰ྔ৯͏Μ͚ͩͲ…ʁ Α͘Θ͔ΒΜ͚Ͳศརʂ ؀ڥߏஙḿΔʂ ରԠ͸ʁ ɾάάΕ͹ରॲ๏͸ग़ͯ͘Δ͕ ɾimageʁ

    containerʁ volumeʁ ɾத਎Λཧղ͠ͳ͍··ίϚϯυΛୟ͘ …
  8. DockerΛ࢖͍࢝Ίͨ͜Ζ ୭͔͕docker-compose.ymlʹ ͓·͡ͳ͍Λॻ͍ͯ͘Εͨʂ Ͱ΋࢖ͬͯΔͱͲΜͲΜ ༰ྔ৯͏Μ͚ͩͲ…ʁ Α͘Θ͔ΒΜ͚Ͳศརʂ ؀ڥߏஙḿΔʂ ରԠ͸ʁ ɾάάΕ͹ରॲ๏͸ग़ͯ͘Δ͕ ɾimageʁ

    containerʁ volumeʁ ɾத਎Λཧղ͠ͳ͍··ίϚϯυΛୟ͘ … த਎Λཧղ্ͨ͠Ͱରॲ͍ͨ͠
  9. ͦΕͧΕͷػೳ

  10. ɹimage Λ pull / build ͯ͠ ɹcontainer ͱ࣮ͯ͠ߦ͢Δ ɹvolume ͸σʔλӬଓԽʹ

    ɹ ࢖ΘΕΔಛघσΟϨΫτϦ
  11. Πϝʔδ͠΍͘͢੔ཧ͢Δͱ

  12. ɹimage → ϓϩάϥϜ ɹcontainer → ϓϩηε ɹvolume → ετϨʔδ ɹ˞ࣗ෼ͳΓʹཧղΛਐΊΔͨΊͷࡶͳ੔ཧͰ͢…

  13. image ɾ࣮ߦՄೳͳܗͰ·ͱΊΒΕͨύοέʔδ ɾΑ͘࢖ΘΕΔ΋ͷ͸ Docker Hub ͱ͍͏ ɹαΠτ͔Βμ΢ϯϩʔυͰ͖Δ (docker pull) ɹ-

    nginx / redis / mysql … ɾࣗ෼Ͱ࡞੒͢Δ͜ͱ΋Ͱ͖Δ (docker build)
  14. image # Ұཡදࣔ
 $ docker images -a # ࢦఆͯ͠࡟আ $

    docker rmi [image] # ࢖ͬͯͳ͍΋ͷ·Δͬͱ࡟আʢv1.2.5 Ҏ߱ʣ $ docker image prune
  15. container ɾಈ͍͍ͯΔϓϩάϥϜͷ࣮ମ ɾimage Λ࣮ߦ͢Δ͜ͱͰੜ੒͞ΕΔ ɾϓϩάϥϜΛ࣮ߦͯ͠ϓϩηε͕૸Δɺతͳ

  16. container # Ұཡදࣔ
 $ docker images -a # ࢦఆͯ͠ఀࢭɺ࡟আ $

    docker stop [container] $ docker rm [container] # ࢖ͬͯͳ͍΋ͷ·Δͬͱ࡟আʢv1.2.5 Ҏ߱ʣ $ docker container prune
  17. volume ɾෳ਺ͷίϯςφ͔ΒࢀরͰ͖Δಛघͳ ɹσΟϨΫτϦ ɾϓϩηεؒͰڞ༗͍ͨ͠σʔλ ɹ- ม਺Ͱ͸ͳ͘ετϨʔδͷΑ͏ͳ ɾvolumeΛհͯ͠σʔλΛϩʔΧϧʹ࣋ͭ͜ͱ ɹͰ container ͕ফ͑ͯ΋σʔλ͸อ࣋

  18. container # Ұཡදࣔ
 $ docker volume ls # ࢦఆͯ͠ఀࢭɺ࡟আ $

    docker volume rm [volume] # ࢖ͬͯͳ͍΋ͷ·Δͬͱ࡟আʢv1.2.5 Ҏ߱ʣ $ docker volume prune
  19. ͭ·Γ݁ہ ɾ·ͣ container Λఀࢭ&࡟আ ɾ͍࣍Ͱ image / volume Λ࡟আ ɹ-

    volume ͸ container ͷ࡟আ࣌ʹ -v Ͱ΋ ɾγεςϜͷ࿩Ͱݴ͑͹… ϓϩηεΛ kill ͔ͯ͠ΒϓϩάϥϜͷ ϑΝΠϧ΍DBΛ࡟আ͢Δɺͱ͍͏࿩
  20. ͪͳΈʹ ɾDocker for mac ࢖ͬͯΔͱ Docker.qcow2 ɹͱ͍͏ϑΝΠϧ͕ංେԽ͢Δ ɾ࡟আͳΓѹॖͳΓͪ͜Β΋ཁରԠ ɹ- v1.13

    Ҏ߱͸ఆظతʹѹॖ͞Ε͍ͯΔʢʁʣ # ஔ͍ͯ͋ΔσΟϨΫτϦ $ ll ~/Library/Containers/com.docker.docker/ Data/com.docker.driver.amd64-linux/ Docker.qcow2
  21. ݁࿦

  22. ͪΌΜͱυΩϡϝϯτಡΉ΂͠ https://docs.docker.com/

  23. ࣗݾ঺հ ɾKeisuke Nakatane (@ksk1030) ɾORSO Inc. ৽نࣄۀ։ൃࣨ ɾαʔόɿΞϓϦɿϑϩϯτ ʹɹ̓ɹɿɹ̍ɹɿɹ̎ɹɹ͘Β͍ ɾલ৬͸ژ౎ͷήʔϜ԰Ͱਓࣄ

    ɾΤϯδχΞੵۃ࠾༻தʂʂ
  24. Thank you for listening !!