Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Dockerを使ってみよう / #kosenconf131hokkaido
Search
さたけ
August 17, 2019
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Dockerを使ってみよう / #kosenconf131hokkaido
さたけ
August 17, 2019
More Decks by さたけ
See All by さたけ
Packer で自分だけの Raspberry Pi イメージを 作った話 / #techstudygroupjp 2020.5.14
satackey
0
430
GitHubとCircleCIで過去問管理 / #aosc 2019-12-21
satackey
0
75
Cloud Foundry を使ってみた / #aosc 2018-02-23
satackey
0
35
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
170
4 Signs Your Business is Dying
shpigford
187
22k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Speed Design
sergeychernyshev
33
1.9k
GitHub's CSS Performance
jonrohan
1033
470k
The Invisible Side of Design
smashingmag
301
52k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
Technical Leadership for Architectural Decision Making
baasie
3
430
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
Transcript
DockerΛ ͬͯΈΑ͏ ࠤ ߤر
ࣗݾհ • খߴઐ 2 ใܥ • ߴઐϓϩίϯڝٕ෦ • AtCoder(Python)ɺ WebϑϩϯτΤϯυɺ
όοΫΤϯυ ͳͲ͍Ζ͍Ζ… @satakenkoki
ࠓͷඪ • DockerΛΒͳ͍ਓɺॳ৺ऀͷਓʹ ͔Δʙ͘ɺΘ͔ͬͯΒ͏ɻ (DockerΛ͍͜ͳͯ͠Δਓɺؒҧ͍ͬͯΔ ͱ͜Ζ͕͋Εࢦఠͯ͘͠ΕΔͱخ͍͠Ͱ͢)
ԾԽͱʁ
• ͬ͘͟Γݴ͏ͱɺ̍ͷίϯϐϡʔλΛɺ ෳ͋Δ͔ͷ༷ʹ͏͜ͱɻ https://www.infraexpert.com/study/virtual.html
ࣗͷPCͷ্ʹ ͞ΕͨڥΛ࡞ΕΔ
• ͬ͘͟Γݴ͏ͱɺ̍ͷίϯϐϡʔλΛɺ ෳ͋Δ͔ͷ༷ʹ͏͜ͱɻ https://www.infraexpert.com/study/virtual.html ήετଆ ϗετଆ
Dockerͱʁ
https://www.docker.com/resources/what-container ͦΕͧΕʹ ͋Δ͔Β ແବ ࠓ·ͰͷԾԽ
• ͬ͘͟Γݴ͏ͱɺ̍ͷίϯϐϡʔλΛɺ ෳ͋Δ͔ͷ༷ʹ͏͜ͱɻ https://www.infraexpert.com/study/virtual.html
https://www.docker.com/resources/what-container ͦΕͧΕʹ ͋Δ͔Β ແବ ࠓ·ͰͷԾԽ
ίϯςφܕԾԽ https://www.docker.com/resources/what-container ࠓ·ͰͷԾԽ ແବ͕ͳ͘ͳͬͨ
ແବ͕ͳ͍ ↓ Ϧιʔεফඅྔ͕গͳ͍ σΟεΫ༻ྔ͕গͳ͍ ↓ ίϯϐϡʔλʹ༏͍͠
ࣗͷPCͷ্ʹ ͞ΕͨڥΛ ܰྔʹ ࡞ΕΔ
ίϯςφܕԾԽ https://www.docker.com/resources/what-container ࠓ·ͰͷԾԽ
Dockerίϯςφͱݺͼ·͢ https://www.docker.com/resources/what-container
Dockerίϯςφͱݺͼ·͢ https://www.docker.com/resources/what-container Dockerίϯςφ DockerΠϝʔδΛݩʹ ىಈ͞Ε·͢
Docker ΠϝʔδΛ༻ҙ͢Δ • Docker Hubͱ͍͏αʔϏεʹ ͨ͘͞Μͷਓ͕࡞ͬͨɺ ༷ʑͳΠϝʔδ͕ެ։͞Ε͍ͯ·͢ɻ • DockerfileΛ͍ɺDocker HubͷΠϝʔδΛݩʹ
ࣗͰDockerΠϝʔδΛ࡞Δ͜ͱͰ͖·͢ɻ • ࣗͰ࡞ͬͨΠϝʔδΛެ։͢Δ͜ͱͰ͖·͢ɻ
PythonΛಈ͔ͯ͠ΈΔ print("Hello, world") # pythonͷΠϝʔδΛݩʹ͢Δ FROM python:3.7 # Helloworld.pyΛίϯςφʹίϐʔ COPY
helloworld.py / # ίϯςφىಈ࣌ʹ࣮ߦ͢ΔίϚϯυΛࢦఆ CMD ["python", "/helloworld.py"] Dockerfile Helloworld.py
͜ͷ̎ͭͷϑΝΠϧΛ ಉ͡ॴʹஔ͖·͢
$ # Docker ΠϝʔδΛ $ # python-hello-world ͱ͍͏໊લͰ࡞͢Δ $ docker
build -t python-hello-world . # ...লུ $ # python-hello-world ͱ͍͏ $ # DockerΠϝʔδΛ࣮ߦ͢Δ $ docker run python-hello-world Hello, world
DockerͷϝϦοτ • DockerfileͳͲΛ༻͍Δ͜ͱʹΑΓɺ ಉ͡ίʔυ͔Βಉ͡ڥΛ؆୯ʹ࡞ΕΔ • ࠓ·ͰͷԾԽΑΓɺ༰ྔ͕গͳ͍ͷͰ ڞ༗͕༰қ
DockerͰ࣮ߦͰ͖͚ͨͲɺ ࡞ͨ͠ϑΝΠϧͲ͏͢Δ?
ਵ࣌มΘΔσʔλ?
Bind mounts / Volumes • Bind mounts ϗετͷϑΝΠϧɾσΟϨΫτϦΛ ίϯςφʹϚϯτ͢Δػೳ •
Volumes Docker͕ཧ͢ΔྖҬΛ ίϯςφʹϚϯτ͢Δػೳ
Bind mounts / Volumes • Bind mounts ϗετͷϑΝΠϧɾσΟϨΫτϦΛ ίϯςφʹϚϯτ͢Δػೳ •
Volumes Docker͕ཧ͢ΔྖҬΛ ίϯςφʹϚϯτ͢Δػೳ ίϚϯυ࣮ߦ࣌ʹ -v /path/to/dir:/path/to/conteiner
$ # Docker ΠϝʔδΛ $ # python-hello-world ͱ͍͏໊લͰ࡞͢Δ $ docker
build -t python-hello-world . # ...লུ $ # python-hello-world ͱ͍͏ $ # DockerΠϝʔδΛ࣮ߦ͢Δ $ docker run python-hello-world Hello, world ͖࣮ͬ͞ߦͨ͠ίʔυ
$ docker run \ # ݱࡏͷσΟϨΫτϦΛίϯςφͷ/dirʹϚϯτ -v ${PWD}:/dir \ python:3.7
\ # ࣮ߦ͢ΔίϚϯυ python /dir/helloworld.py Hello, world Bind mount Λ͑͜Ε͚ͩ
DockerίϯςφΛ͏ͱ͖ • DockerͷίϯςφΛѻ͏ࡍɺ σʔλ֎෦ʹஔ͘ͷ͕جຊ • 1ίϯςφ1ϓϩηε͕جຊ →࠶ར༻ͳͲ͕؆୯ʹͳΔ
͞Βʹ • DockerΛͬͯɺࣗͷΞϓϦέʔγϣϯΛ ެ։͢Δ • Dockerͷڥ͑͋͞Εɺ ෳࡶͳઃఆͳ͠ʹ୭Ͱಈ͔ͤΔ
·ͱΊ • DockerܰྔͰɺ͞ΕͨڥΛ࡞ΕΔ • DockerfileͳͲΛͬͯɺDockerΠϝʔδΛ ࡞͠ɺDockerίϯςφΛ࡞͢Δ • ڥͷڞ༗࠶ߏங͕༰қ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠!