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
Droot Internals
Search
Yuuki Tsubouchi (yuuk1)
April 23, 2016
Technology
3
20k
Droot Internals
id:y_uuki
第9回 コンテナ型仮想化の情報交換会@福岡
Yuuki Tsubouchi (yuuk1)
April 23, 2016
Tweet
Share
More Decks by Yuuki Tsubouchi (yuuk1)
See All by Yuuki Tsubouchi (yuuk1)
MetricSifter:クラウドアプリケーションにおける故障箇所特定の効率化のための多変量時系列データの特徴量削減 / FIT 2024
yuukit
2
140
工学としてのSRE再訪 / Revisiting SRE as Engineering
yuukit
19
12k
Cloudless Computingの論文紹介
yuukit
2
440
#SRE論文紹介 Detection is Better Than Cure: A Cloud Incidents Perspective V. Ganatra et. al., ESEC/FSE’23
yuukit
3
1.5k
エンジニアのためのSRE論文への招待 / Introduction to SRE Papers for Engineers
yuukit
2
11k
博士課程での研究まとめ 2023年1月版 / Summary of my research in the PhD course
yuukit
1
260
AI時代に向けたクラウドにおける信頼性エンジニアリングの未来構想 / DICOMO2022 6A-1
yuukit
7
2.9k
AIOps研究録―SREのための システム障害の自動原因診断 / SRE NEXT 2022
yuukit
10
12k
Interactive AIOps
yuukit
0
2.1k
Other Decks in Technology
See All in Technology
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
250
Snowflake女子会#3 Snowpipeの良さを5分で語るよ
lana2548
0
220
AIのコンプラは何故しんどい?
shujisado
1
190
How to be an AWS Community Builder | 君もAWS Community Builderになろう!〜2024 冬 CB募集直前対策編?!〜
coosuke
PRO
2
2.8k
ずっと昔に Star をつけたはずの思い出せない GitHub リポジトリを見つけたい!
rokuosan
0
150
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
podman_update_2024-12
orimanabu
1
260
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
210
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
470
5分でわかるDuckDB
chanyou0311
10
3.2k
LINEヤフーのフロントエンド組織・体制の紹介【24年12月】
lycorp_recruit_jp
0
530
Wantedly での Datadog 活用事例
bgpat
1
400
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
Mobile First: as difficult as doing things right
swwweet
222
9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Code Reviewing Like a Champion
maltzj
520
39k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.3k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
The Invisible Side of Design
smashingmag
298
50k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Unsuck your backbone
ammeep
669
57k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Agile that works and the tools we love
rasmusluckow
328
21k
Transcript
%SPPU*OUFSOBMT JEZ@VVLJ ୈ̕ճίϯςφܕԾԽͷใަձ!Ԭ
id:y_uuki @y_uuk1 ͯͳ!ژ ΣϒΦϖϨʔγϣϯΤϯδχΞ
IUUQZVVLJIBUFOBCMPHDPNFOUSZESPPU
TL;DR • ιϑτΣΞґଘࠈͷղܾͷͨΊʹ DockerΛ͍͍ͨ • ຊ൪ڥͰDockerΛӡ༻͢ΔͷͭΒ͍ • ʮBuild, Ship, Runʯͱ͍͏ίϯηϓτ͖
• DockerΠϝʔδΛS3Λܦ༝ͯ͠͠ɺ chrootͰ࣮ߦ͢Δख๏ͷఏҊ
ԾԽٕज़ )8ԾԽ 04ԾԽ ,7. 9FO ʜ γεςϜίϯςφ -9$ ΞϓϦέʔγϣϯ ίϯςφ
%PDLFS
ͳͥ()DockerΛ͏ͷ͔ • ✘ VMΑΓߴ • ✘ Πϛϡʔλϒϧ • ✘ Φʔτεέʔϧ
• ˚ ϙʔλϏϦςΟ • ◦ ϓϩάϥϚϒϧͳϗετڥ • ◦ ιϑτΣΞґଘࠈͷղܾ
ιϑτΣΞґଘࠈ • ͋ΔιϑτΣΞ͍͍ͨͯෳͷιϑτ ΣΞʹґଘ͢Δ • ґଘઌͷιϑτΣΞ·ͨෳͷιϑτ ΣΞʹґଘ͢Δ • ಉ͡ڥΛ࠶ݱ͢Δͷ͕͍͠ •
BundlerͳͲΛͬͯCͷϥΠϒϥϦʹ ґଘ͢Δ͜ͱ
Docker • LinuxͷσΟετϦϏϡʔγϣϯڥ ͝ͱݻΊͯΠϝʔδԽ • /lib, /usr/bin, /etcͳͲͥΜͿ • Linux
NamespacesͰಠཱͨ͠ڥΛ ࡞ͬͯΠϝʔδΛల։
DockerࠔΔ͜ͱ • Docker Engineͷෆ҆ఆ͞ • ωοτϫʔΫ·ΘΓͷύϑΥʔϚϯεྼԽ • ίϯςφͷΰϛআ • ίϯςφͷແఀࢭσϓϩΠ
• ίϯςφͷϩάཧ • ίϯςφͷࢹ • ίϯςφͷσόοά • Docker Registryͷӡ༻
chroot
chroot ☓ Docker ͷΞΠσΞ EPDLFSQVMMNZTRM $0/5"*/&3@*% EPDLFSDSFBUFNZTRM EPDLFSFYQPSU$0/5"*/&3@*%PNZTRMUBS NZTRMUBSΛ.Z42-Λಈ͔͍ͨ͠ϗετίϐʔ
͢Δɻ UBSYG[WBSDPOUBJOFSTNZTRMNZTRMUBS TVEPDISPPUWBSDPOUBJOFSTNZTRMNZTRME
None
࠷ۙͷΞϓϦέʔγϣϯσϓϩΠ • git pull͕͍ • σϓϩΠαʔό͔Βͷrsync͍ • tarball σϓϩΠ •
ՌΛS3ͳͲʹஔ͠ɺσϓϩΠઌͰ s3 cp Ͱμϯϩʔυͯ͠ల։ • Serf/Consul • σϓϩΠαʔό͔ΒͷSSH͕͍ͨΊ
Droot
#VJME 4IJQ 3VO ESPPUSVO EPDLFSCVJME ESPPUFYQPSU EPDLFS EBFNPO 4UPSBHF 4
ESPPUEFQMPZ BXTTDQ BXTTDQ
%PDLFS %SPPU #VJME EPDLFSCVJME EPDLFSCVJME 3FHJTUSZ %PDLFS)VC %JTUSJCVUJPO ͳΜͰΑ͍ "NB[PO4
'JMF'PSNBU %PDLFSJNBHF ͳΜͰΑ͍ FYUBSH[ $POUBJOFS -JOVY /BNFTQBDFT DISPPU
$ droot export • DockerΠϝʔδͷϑΝΠϧγεςϜΛtarܗࣜͰग़ྗ • جຊ docker create &&
docker export • gzip / aws cli ͱͷύΠϓʹΑΓɺtar.gzԽͯ͠S3ʹஔ • ϑΝΠϧγεςϜʹdrootઐ༻ͷڥมϑΝΠϧ (/.drootenv) ΛࠐΉ ESPPUFYQPSUEPDLFSpMFTBQQcH[JQDR cBXTTDQTCVDLFUBQQUBSH[
$ droot deploy • ඪ४ೖྗ͔ΒtarΞʔΧΠϒΛಡΈࠐΈɺࢦఆ͠ ͨσΟϨΫτϦʹల։ • සൟʹߋ৽͞ΕΔίϯςφͷσϓϩΠΛఆ • rsync
mode ͱ symlink mode BXTTDQTCVDLFUBQQUBSH[c HVO[JQDRcESPPUEFQMPZSPPUWBSDPOUBJOFST
symlink ʹΑΔ atomic deploy • σϓϩΠࡁΈͷίϯςφ ڥΛࠩ͠ସ͑Δඞཁ͕͋Δ • https://gist.github.com/ datagrok/3807742#file-
symlink-replacement-md • symlink Λ rename(2)ɹ (mv -T) ͰΓସ͑Δ͜ͱ ʹΑΓΞτϛοΫʹσΟϨ ΫτϦΛࠩ͠ସ͑Δ ᵓᴷᴷBQQBQQENBJO ᵓᴷᴷBQQE ᵋᴷᴷNBJO ᵋᴷᴷCJO ᵋᴷᴷCPPU ᵋᴷᴷEFW ᵋᴷᴷCBDLVQ ᵋᴷᴷCJO ᵋᴷᴷCPPU ᵋᴷᴷEFW
$ droot run • ࢦఆͨ͠σΟϨΫτϦΛchroot jailͱ࣮ͯ͠ߦ • σόΠεϑΝΠϧͷ࡞ (/dev/null, /dev/zeroͳͲ)
• ϗετͷ /etc/group, /etc/resolve.confͳͲΛίϐʔ • bind mountͰϗετଆͷҙͷσΟϨΫτϦΛϚϯτ • Linux capabilities(7) ͰݖݶΛ੍ TVEPESPPUSVODQCJOEWBSMPHSPPU ɹɹWBSDPOUBJOFSTBQQDPNNBOE
chroot(2) • ϓϩηεͷϧʔτσΟϨΫτϦΛมߋ • ϓϩηεͷઈରύεͷ୳ࡧىͷมߋͷΈ • ϓϩηεΛੜͨ͠Γ͠ͳ͍ • ΧϨϯτσΟϨΫτϦͦͷ··ͳͷͰcrhootίʔ ϧޙʹchdir(“/“)͢Δ͜ͱ͕ଟ͍
• jailڥ֎ͷϑΝΠϧషΒΕͨγϯϘϦοΫϦϯ ΫΞΫηεͰ͖ͳ͍
BindϚϯτ • Linux 2.2͔Βಋೖ • σΟϨΫτϦϑΝΠϧΛଞͷҐஔϚϯτ • chroot jailڥ͔ΒϚϯτઌͷϑΝΠϧσΟϨ ΫτϦΞΫηεͰ͖Δ
• /var/containers/app/var/log ͱ͔ࢀর͢Δͷ໘ • mount -o bind /var/log /var/containers/app/var/log • ϗετͷ /var/log Λڞ༗
LinuxέʔύϏϦςΟ • chroot(2)ಛݖϓϩηεͰͳ͍ͱίʔϧͰ͖ͳ͍ • (ݫີʹCAP_SYS_CHROOT) • ͔͠͠ɺεʔύʔϢʔβͰಈ͔͢ͷෆ҆ • εʔύʔϢʔβͰಈ͔ͭͭ͠ɺcapabilities(7)Ͱඞཁͳ ݖݶҎ֎Λམͱ͓ͯ͘͠
• CAP_CHOWN, CAP_DAC_OVERRIDE, CAP_DAC_READ_SEARCH, CAP_FOWNER, CAP_SETGID, CAP_SETUID, CAP_NET_BIND_SERVICE ΛڐՄ
Problems
• Docker (NamespacesΛͬͨίϯςφ)΄Ͳͷɹ ϙʔλϏϦςΟͳ͍ • Dockerίϯςφͷڥม͕Ҿ͖ܧ͕Εͳ͍ • Dockerίϯςφ্ͷ user/group ͕σϓϩΠઌ
ϗετʹ͍ͳ͍ ϙʔλϏϦςΟͷ
• ڥมϑΝΠϧͱͯ͠ӬଓԽ͞Εͳ͍ͷͰɺ Ұ୴ϑΝΠϧʹอଘ • droot export ͰҰ୴Dockerίϯςφͱͯ͠ىಈ͞ ͔ͤͯΒ env ίϚϯυͷ࣮ߦ݁ՌΛ
/.drootenv ͱ ͯ͠อଘ • droot run Ͱ /.drootnenv ΛಡΈͩͯ͠ڥมΛ ෮ݩ • droot run —env ͰڥมͷՃɾ্ॻ͖Մೳ ڥมͷҾ͖ܧ͗
• User NamespacesͰ/etc/groupͳͲΛΈͯඞཁ ͳuser/grpupΛࣗಈ࡞ • ϓϩηεπϦʔߏΛ͔͑ͨ͘ͳ͍ͷͰɺclone(2) Ͱͳ͘ chroot(2) ޙʹ unshare(2)
͢Δ • clone(2) ͩͱࢠϓϩηεΛੜ͢ΔͨΊɺεʔ ύʔόΠβϓϩηεͷԼͰdroot runͨ͠ͱ͖ ʹɺγάφϧཧ͕͏·͍͔͘ͳ͍͔ user/groupͷࣗಈ࡞(ະ࣮)
• ͜Ε͓ͦΒ͘ PID Namespacesͷ • https://lwn.net/Articles/532748/ • NamespacesԼͷϓϩηε͕pid 1ͱͯ͠ৼΔ͏ඞཁ͕Ͱ ͯ͘Δ
• orphanϓϩηεͷճऩ͢Δඞཁ͕͋Δ
ίϯςφ ࣗͰ࡞ΕΔ
(PMBOH
• github.com/docker/docker/pkg • archive, devicemapper, fileutils, mount, symlink… • github.com/opencontainers/runc/libcontainer
• Linux Namespaces·ΘΓ • https://github.com/syndtr/gocapability • LinuxέʔύϏϦςΟ • github.com/docker/engine-api • Docker APIΫϥΠΞϯτ ίϯςφπʔϧ͚ύοέʔδ
• ࣗ࡞ͷίϯςφπʔϧ Drootͷഎܠͱ࣮ • Build, Ship, RunΛ࣮ݱ͢Δୈ̏ͷιϑτΣΞ • droot export,
droot deploy, droot run • DockerͰΠϝʔδΛ࡞ͬͯ chroot Ͱ࣮ߦ • ϙʔλϏϦςΟͷͱͦͷղܾ • ίϯςφࣗͰ࡞ΕΔ ·ͱΊ
github.com/yuuki/droot