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)
博士学位論文予備審査 / Scaling Telemetry Workloads in Cloud Applications: Techniques for Instrumentation, Storage, and Mining
yuukit
1
1.6k
MetricSifter:クラウドアプリケーションにおける故障箇所特定の効率化のための多変量時系列データの特徴量削減 / FIT 2024
yuukit
2
160
工学としてのSRE再訪 / Revisiting SRE as Engineering
yuukit
19
12k
Cloudless Computingの論文紹介
yuukit
2
460
#SRE論文紹介 Detection is Better Than Cure: A Cloud Incidents Perspective V. Ganatra et. al., ESEC/FSE’23
yuukit
3
1.6k
エンジニアのためのSRE論文への招待 / Introduction to SRE Papers for Engineers
yuukit
2
11k
博士課程での研究まとめ 2023年1月版 / Summary of my research in the PhD course
yuukit
1
270
AI時代に向けたクラウドにおける信頼性エンジニアリングの未来構想 / DICOMO2022 6A-1
yuukit
7
2.9k
AIOps研究録―SREのための システム障害の自動原因診断 / SRE NEXT 2022
yuukit
10
12k
Other Decks in Technology
See All in Technology
AWS re:Invent 2024 re:Cap Taipei (for Developer): New Launches that facilitate Developer Workflow and Continuous Innovation
dwchiang
0
140
comilioとCloudflare、そして未来へと向けて
oliver_diary
5
420
Building Scalable Backend Services with Firebase
wisdommatt
0
110
OPENLOGI Company Profile for engineer
hr01
1
18k
デジタルアイデンティティ技術 認可・ID連携・認証 応用 / 20250114-OIDF-J-EduWG-TechSWG
oidfj
2
520
商品レコメンドでのexplicit negative feedbackの活用
alpicola
1
300
デジタルアイデンティティ人材育成推進ワーキンググループ 翻訳サブワーキンググループ 活動報告 / 20250114-OIDF-J-EduWG-TranslationSWG
oidfj
0
380
Fabric 移行時の躓きポイントと対応策
ohata_ds
1
150
30分でわかるデータ分析者のためのディメンショナルモデリング #datatechjp / 20250120
kazaneya
PRO
21
4.6k
Azureの開発で辛いところ
re3turn
0
240
FODにおけるホーム画面編成のレコメンド
watarukudo
PRO
2
200
駆け出しリーダーとしての第一歩〜開発チームとの新しい関わり方〜 / Beginning Journey as Team Leader
kaonavi
0
120
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Designing for Performance
lara
604
68k
Into the Great Unknown - MozCon
thekraken
34
1.6k
Making the Leap to Tech Lead
cromwellryan
133
9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Mobile First: as difficult as doing things right
swwweet
222
9k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Faster Mobile Websites
deanohume
305
30k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
570
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