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
Better Docker Image
Search
Recruit Technologies
October 12, 2018
Technology
1
3.8k
Better Docker Image
2018/10/12 フューチャーアーキテクトとのLTバトルでの、與那城(@orisano)の講演資料になります
Recruit Technologies
October 12, 2018
Tweet
Share
More Decks by Recruit Technologies
See All by Recruit Technologies
障害はチャンスだ! 障害を前向きに捉える
rtechkouhou
1
640
Flutter移行の苦労と、乗り越えた先に得られたもの
rtechkouhou
3
11k
ここ数年間のタウンワークiOSアプリのエンジニアのチャレンジ
rtechkouhou
1
1.5k
大規模環境をAWS Transit Gatewayで設計/移行する前に考える3つのポイントと移行への挑戦
rtechkouhou
1
1.9k
【61期 新人BootCamp】TOC入門
rtechkouhou
3
41k
【RTC新人研修 】 TPS
rtechkouhou
1
41k
Android Boot Camp 2020
rtechkouhou
0
41k
HTML/CSS
rtechkouhou
10
50k
TypeScript Bootcamp 2020
rtechkouhou
9
45k
Other Decks in Technology
See All in Technology
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
160
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
420
安心してください、日本語使えますよ―Ubuntu日本語Remix提供休止に寄せて― 2024-11-17
nobutomurata
1
1k
The Role of Developer Relations in AI Product Success.
giftojabu1
0
130
OTelCol_TailSampling_and_SpanMetrics
gumamon
1
200
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
4
230
複雑なState管理からの脱却
sansantech
PRO
1
150
Platform Engineering for Software Developers and Architects
syntasso
1
520
Taming you application's environments
salaboy
0
190
Introduction to Works of ML Engineer in LY Corporation
lycorp_recruit_jp
0
140
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.2k
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
150
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
334
57k
Automating Front-end Workflow
addyosmani
1366
200k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Typedesign – Prime Four
hannesfritz
40
2.4k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
How to Ace a Technical Interview
jacobian
276
23k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
130
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Music & Morning Musume
bryan
46
6.2k
A Tale of Four Properties
chriscoyier
156
23k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Transcript
Better Docker Image Container Build Meetup #1 #container_build @orisano
ྑ͍Docker ImageͱԿ͔
αʔϏεʹؔΘΔਓΛ ͤʹ͢ΔΠϝʔδ
ݟͯΘ͔Γ͍͢ खݩͰߴʹbuild͞ΕΔ CI্Ͱߴʹbuild͞ΕΔ ߴʹdeploy͞ΕΔ
ࠓ͍ͨ͜͠ͱ
ͲͷΑ͏ʹ͘͢Δ͔ ͲͷΑ͏ʹখ͘͢͞Δ͔
ͲͷΑ͏ʹ͘͢Δ͔ ͲͷΑ͏ʹখ͘͢͞Δ͔
ͲͷΑ͏ʹ͘͢Δ͔ • ΠϝʔδΛখ͘͢͞Δ • ίϚϯυͦͷͷΛ͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ •
ඞཁͳ͍εςʔδΛbuild͠ͳ͍
ͲͷΑ͏ʹ͘͢Δ͔ • ΠϝʔδΛখ͘͢͞Δ • ίϚϯυͦͷͷΛ͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ •
ඞཁͳ͍εςʔδΛbuild͠ͳ͍
imageΛখ͘͢͞Δͷ docker push͢Δͱ͖ͷ docker pull͢Δͱ͖ͷ ͷߴԽʹͭͳ͕Δ
Ͳͷ༷ʹখ͘͢͞Δ͔ ͋ͱͰ
ͲͷΑ͏ʹ͘͢Δ͔ • ΠϝʔδΛখ͘͢͞Δ • ίϚϯυͦͷͷΛ͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ •
ඞཁͳ͍εςʔδΛbuild͠ͳ͍
ίϚϯυͦͷͷΛ͘͢Δ
URLʹର͢ΔADDΛΘͳ͍ RUNͷதΛ͘͢Δ
URLʹର͢ΔADDΛΘͳ͍ RUNͷதΛ͘͢Δ
URLʹର͢ΔADD جຊతʹμϯϩʔυ͢Δ
͍
ΞΫηε͍ͯ͠Δઌͷ ίϯςϯπ͕ႈͳΒ wget + gzip + tarͰे
`RUN wget`ʹ͢Δ͜ͱͰ cache͕ޮ͘
ႈͰͳ͍Ϧιʔεʹ ґଘ͢ΔͷΛۃྗΊΔ
URLʹର͢ΔADDΛΘͳ͍ RUNͷதΛ͘͢Δ
GitHub͔Β࣮ߦϑΝΠϧΛ curl or wgetͰऔಘ͢Δ ͕͍
Ͳ͏ʹ͔͘Ͱ͖ͳ͍͔ curl -vvvΛ͏ͬͯΈͨ
GitHub ReleaseS3Ͱ͋Δ S3Accept-Ranges: bytes ͱ͍͏͜ͱ͕Θ͔ͬͨ
Accept-Ranges: bytes ͬͯͳΜͩΖ͏
RFC7233, Range Requests ൣғΛࢦఆͯ͠ downloadͰ͖Δ
ͭ·Γ ฒྻμϯϩʔυ͕Մೳ
github.com/orisano/rget
None
ڥʹΑΓ·͕͢ 5min -> 2min
DockerfileͷҎ֎ʹ ͘͢ΔΞϓϩʔν͋Δ
ͲͷΑ͏ʹ͘͢Δ͔ • ΠϝʔδΛখ͘͢͞Δ • ίϚϯυͦͷͷΛ͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ •
ඞཁͳ͍εςʔδΛbuild͠ͳ͍
cacheΛޮ͔ͤΔ
docker build͢ΔϚγϯ͕ ಉҰͷ߹ ಉҰͰͳ͍߹
docker build͢ΔϚγϯ͕ ಉҰͷ߹ ಉҰͰͳ͍߹
cacheͷΈΛཧղ͢Δ
RUN จࣈྻ͕มΘΒͳ͍ݶΓ جຊతʹcache͞ΕΔ
COPY, ADD͢ΔϑΝΠϧͷ ༰͕มΘͬͨ߹ Ҏ߱ͷRUNͷcache͕ഁغ
ͳͷͰ lockfileͳͲΛઌʹίϐʔͯ͠ install͚ͩͯ͠cacheͤ͞Δ
None
None
docker build͢ΔϚγϯ͕ ಉҰͷ߹ ಉҰͰͳ͍߹
CI্Ͱbuild͢Δͱ͖ͳͲ cache͕ͳ͍͜ͱ͕ଟ͍
docker save & load or docker pull docker build —cache-from
Λ͏
image͕େ͖͍/layer͕ଟ͍ ߹ buildͷ΄͏͕ૣ͍͜ͱ͋Δ
image͕େ͖͍/layer͕ଟ͍ ߹ buildͷ΄͏͕ૣ͍͜ͱ͋Δ ܭଌܾͯ͠ΊΔ
ͲͷΑ͏ʹ͘͢Δ͔ • ΠϝʔδΛখ͘͢͞Δ • ίϚϯυͦͷͷΛ͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ •
ඞཁͳ͍εςʔδΛbuild͠ͳ͍
ґଘͷͳ͍εςʔδΛ ฒྻͰ࣮ߦ͢Δ
buildkitΛ͍ͬͯͩ͘͞ʂ github.com/moby/buildkit export DOCKER_BUILDKIT=1
ͲͷΑ͏ʹ͘͢Δ͔ • ΠϝʔδΛখ͘͢͞Δ • ίϚϯυͦͷͷΛ͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ •
ඞཁͳ͍εςʔδΛbuild͠ͳ͍
ඞཁͳ͍εςʔδΛ build͠ͳ͍
—targetΛ͑Α͍ͷͰʁ
—target ࢦఆͨ͠εςʔδҎલΛ શ෦build͢Δ
multi stage buildΛ ౿ΈࠐΜ͍ͩํ͍ͯ͠Δͱ ૺ۰͕ͪ͠
͓ͦΒ͘buildkitͰͰ͖Δ͕ buildkit͕͑ͳ͍߹ʹ
github.com/orisano/targd • DockerfileͷASTΛऔಘ • ࢦఆ͞ΕͨεςʔδͷґଘεςʔδΛநग़ • ґଘεςʔδ͚ͩͷDockerfileΛग़ྗ
github.com/orisano/targd
ͲͷΑ͏ʹ͘͢Δ͔ ͲͷΑ͏ʹখ͘͢͞Δ͔
ͲͷΑ͏ʹখ͘͢͞Δ͔ • multi stage buildΛ͏ • RUNΛ·ͱΊΔ(?) • ͳͥେ͖͍͔ΛΔ
ͲͷΑ͏ʹখ͘͢͞Δ͔ • multi stage buildΛ͏ • RUNΛ·ͱΊΔ(?) • ͳͥେ͖͍͔ΛΔ
multi stage buildΛ͏
multi stage buildͰ ͋Γ͕ͪͳٙ
࠷ऴతͳΠϝʔδ͕ খ͘͞ͳΔ͔Β ͦΕ·Ͱͷεςʔδ ࠷దԽ͠ͳͯ͘ྑ͍ʁ
None
ݸਓతʹNo
moby/issues/34715 —cache-formͩͱ multi stage buildͷ લஈͷεςʔδͷcache͕ ޮ͔ͳ͍
࠷ऴεςʔδ͔͠ pushͯ͠ͳ͍͔ΒͨΓલ
CI্Ͱͷbuild —cache-fromΛ͏ ࠷ऴεςʔδ͚ͩcache͢Δ ҙຯͳ͍
multi stage build࣌ʹ cacheΛޮ͔͍ͤͨ߹ લͷεςʔδ ໌ࣔతʹpush͢Δ͔͠ͳ͍
݁ہpush͢ΔͷͰ push/pullͷίετ͕͔͔Δ ͯ͢ͷεςʔδΛฏʹ খ͖͘͢͞ (ݸਓͷݟղͰ͢)
ͲͷΑ͏ʹখ͘͢͞Δ͔ • multi stage buildΛ͏ • RUNΛ·ͱΊΔ(?) • ͳͥେ͖͍͔ΛΔ
RUNΛ·ͱΊΔ(?)
Ͳ͔ͬʔ;͍͊Δ 1ͭͷRUNʹ શ෦ॻ͘ͱྑ͍Β͍͠(?)
github.com/orisano/minid • DockerfileͷASTΛऔಘ • ࿈ଓ͢ΔRUN, COPY, ADDΛ࿈݁͢Δ • ݁ՌͷDockerfileΛग़ྗ
github.com/orisano/minid
αΠζ͕খ͘͞ͳͬͨ
ͰͳΜͰʁ
ϨΠϠʔͷΦʔόʔϔου͕ ݮΔ͔Βখ͘͞ͳΔʁ
͍͍͑
·ͣ Ͳ͏͍͏ܗͰอଘ͞ΕͯΔ͔ ΛΔ
moby/image/spec/v1.md
AUFS
http://docs.docker.jp/engine/userguide/storagedriver/aufs-driver.html
আ whiteoutϑΝΠϧͷՃ Ҡಈ opaqueϑΝΠϧͷՃ ʴ ҠಈઌͷϑΝΠϧࠩ
ҰͰ RUN,COPY,ADDΛލ͙ͱ imageʹͬͯ͠·͏
ػցతʹͰ ҰͭͷRUNʹ·ͱΊΔ͜ͱͰ ༨ܭͳͷΛݮͰ͖Δ
1ͭͷϨΠϠʔʹ ·ͱΊΔ͜ͱ ຊʹਖ਼͍͠ͷ͔
ϨΠϠʔΛผ͚Δ͜ͱʹΑΓ ฒྻμϯϩʔυͷԸܙ cacheͷ༗ޮ׆༻ Մಡੑͷ্
ϨΠϠʔΛผ͚Δ͜ͱʹΑΓ ฒྻμϯϩʔυͷԸܙ cacheͷ༗ޮ׆༻ Մಡੑͷ্ ܭଌܾͯ͠ΊΔ
ͱ͍͑ ෳϨΠϠʔʹ ލ͕Βͳ͍ఔʹ ׂ͢Δͷ͕ྑͦ͞͏
ͲͷΑ͏ʹখ͘͢͞Δ͔ • multi stage buildΛ͏ • RUNΛ·ͱΊΔ(?) • ͳͥେ͖͍͔ΛΔ
ͳͥେ͖͍͔ΛΔ
͍͔ͳΔνϡʔχϯάͰ ܭଌͤͣʹ͍͚ͬͯͳ͍
docker history
docker history
ͲͷϨΠϠʔ͕ େ͖͍͔Θ͔Δ͚Ͳ ͳͥେ͖͍͔͔ΓͮΒ͍
ҙ֎ʹίϚϯυ͕ Ͳ͏͍͏ϑΝΠϧΛ࡞Δͷ͔ Βͳ͍
github.com/orisano/dlayer • docker saveͰಘΒΕͨtarΛղੳ • layerͱcmdͷରԠΛͱΔ • layerͷࠩΛϑΝΠϧαΠζ͕େ͖͍ॱʹද ࣔ
github.com/orisano/dlayer
࣮ࡍʹdlayerΛͬͯ golangެࣜalpineΠϝʔδͷ αΠζΛݮΒͯ͠Έͨ
docker-library/golang/pull/232
None
golang:1.11͔Βtoolchainͷ αΠζ͕Ͱ͔͘ͳͬͨ SSAͰͷ࠷దԽ͕૿͔͑ͨΒʁ
1.10: 253MB
1.11: 305MB
࡞ͬͨπʔϧ • github.com/orisano/rget • github.com/orisano/targd • github.com/orisano/minid • github.com/orisano/dlayer •
ྑ͍ͱࢥͬͨΒελʔ͍͚ͯͨͩ͠ΔͱྭΈʹͳΓ·͢
·ͱΊ • ίϚϯυΛ͘Ͱ͖ͳ͍͔ߟ͑Δ • cacheΛཧղͯ͠༗ޮʹ׆͔͢ (CI or ϩʔΧϧ) • multi
stage buildΛ͏ (ॏ͍stageΛcache͢Δ) • layerΛখ͘͢͞ΔͨΊʹੳ͢Δ • buildkitΛ͏!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
rget͜΅Ε
github.com/orisano/rget
Ͱ ͜ΕͰຊʹ͍͍ΜͩΖ͏͔
rgetͷbinaryΛdownload ͢ΔͷͰෛ͚ͨؾ͕͢Δ()
shell͚ͩͰ ࣮ݱͰ͖ͳ͍ͩΖ͏͔
ϙʔλϒϧੑ͍Βͳ͍ͷͰ ओઓͷalpineʹߜΔ
alpine(busybox) xargs͕ೖ͍ͬͯΔʂʂʂ
xargsΛ͏͜ͱͰ ฒྻԽ ಉ࣌ଓ੍ݶ ͕࣮ݱͰ͖Δ
GitHub Release ؆୯ʹHEAD͕Ͱ͖ͳ͍ͷͰ GETͰbodyΛແࢹͯ͠ Content-LengthΛऔಘͰ͖Δ
seqͰ chunkͷrangeΛੜͰ͖Δ
wget206 Partial Content ͕͏·͘ѻ͑ͳ͍ͷͰμϝ
ํͳ͍ͷͰ curl -RͰdownload
࠷ޙʹcatͯ͠chunkΛ݁߹
shellͰ࣮ݱͰ͖Δʂ
͔͠͠ curlalpineඪ४Ͱͳ͍
apk add —no-cache curl ෛ͚ͨؾ͕͢Δ()
͔͠͠ wget206͕ॲཧͰ͖ͳ͍
ఘΊΒΕͳ͍ͷͰ busyboxͷwgetͷ ιʔείʔυΛಡΉ
busybox/networking/wget.c
busybox/networking/wget.c
-OͰࢦఆͨ͠ϑΝΠϧ͕ଘࡏ (ϑΝΠϧαΠζ͕1Ҏ্) -cΛࢦఆ͍ͯ͠Δ ্هͷ݅Λຬͨ͢ͱ͖ 206Λॲཧͯ͘͠ΕΔ
ͭ·Γ దͳ1byteͷϑΝΠϧʹ -cͰࢦఆ͢Δ͜ͱͰճආՄೳ
ઌ಄ͷ1byteΛऔΓআ͚Ε alpineඪ४ͷΈͰ࣮ݱՄೳ
tailͰՄೳ͕͍ͩ dd skip=1 iflag=skip_bytes ͕ߴ
alpineඪ४ͷΈͰ࣮ݱ
https://github.com/orisano/rget/blob/master/rget.sh