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
0
190
Dockerを使ってみよう / #kosenconf131hokkaido
さたけ
August 17, 2019
Tweet
Share
More Decks by さたけ
See All by さたけ
Packer で自分だけの Raspberry Pi イメージを 作った話 / #techstudygroupjp 2020.5.14
satackey
0
420
GitHubとCircleCIで過去問管理 / #aosc 2019-12-21
satackey
0
66
Cloud Foundry を使ってみた / #aosc 2018-02-23
satackey
0
24
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
The Invisible Side of Design
smashingmag
301
51k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Embracing the Ebb and Flow
colly
86
4.7k
BBQ
matthewcrist
89
9.7k
Into the Great Unknown - MozCon
thekraken
39
1.9k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
510
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
RailsConf 2023
tenderlove
30
1.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
950
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ίϯςφΛ࡞͢Δ • ڥͷڞ༗࠶ߏங͕༰қ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠!