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
Container Build Talk
Search
orisano
July 25, 2019
Programming
2.6k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Container Build Talk
orisano
July 25, 2019
More Decks by orisano
See All by orisano
OSS Performance Tuning Tips
orisano
8
6.2k
Docker-Compose & BuildKit
orisano
4
1.1k
dockerignore talk
orisano
2
7.4k
Better docker image+
orisano
6
6.7k
Socket.IO Introduction
orisano
0
3.3k
Profiling Go Application
orisano
11
8.1k
Multi-stage Builds Patterns & Practice
orisano
6
5.3k
better docker image
orisano
22
31k
the world of characters
orisano
8
1.5k
Other Decks in Programming
See All in Programming
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
2
440
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
360
AWS Transform Customによる Spring Boot 2.xから4.xへのVerUp
satoshi256kbyte
2
100
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
5
1.7k
プロポーザルを書いてもらう
pvcresin
0
580
How I Won Prize Money at a Hackathon Using Codex and Symphony Alpha
yasei_no_otoko
0
120
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
380
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
340
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.7k
Go 1.27 における memory allocation の高速化
andpad
0
320
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
230
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
180
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
A better future with KSS
kneath
240
18k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Design in an AI World
tapps
1
290
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
380
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
800
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
430
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
660
Transcript
Container Buildͷ @orisano
Agenda • docker buildͷ • CI ʹ͓͚Δdocker build • docker
buildʹඞཁͩͬͨͷ
Agenda • docker buildͷ • CI ʹ͓͚Δdocker build • docker
buildʹඞཁͩͬͨͷ
EPDLFSDMJ EPDLFSE HTTP
EPDLFSDMJ EPDLFSE HTTP Mac LinuxKit
EPDLFSDMJ EPDLFSE HTTP Mac LinuxKit $ docker build [build context]
EPDLFSDMJ EPDLFSE HTTP Mac LinuxKit $ docker build [build context]
directoryҎԼΛ.dockerignore Λߟྀͯ͠tarʹ͢Δ
EPDLFSDMJ EPDLFSE HTTP Mac LinuxKit $ docker build [build context]
directoryҎԼΛ.dockerignore Λߟྀͯ͠tarʹ͢Δ tar
Dockerfile
Dockerfile ෳͷεςʔδΛ࣋ͭ εςʔδ ≒ Πϝʔδ
Stage FROM image [AS stage] RUN apk add ca-certificates COPY
package.json . COPY package-lock.json . ENV NODE_ENV=production RUN npm ci COPY . . RUN npm run build
Dockerfile Stage 1 Stage 2 Stage 3
ҰͷbuildͰ࡞ΕΔͷ 1Πϝʔδ͚ͩ
جຊతʹ ࠷ޙͷεςʔδ͕ग़ྗ͞ΕΔ
Dockerfile Stage 1 Stage 2 Stage 3
—targetͰࢦఆ͢Δͱ ग़ྗΠϝʔδΛܾΊΒΕΔ
Dockerfile Stage 1 Stage 2 Stage 3 —target
Πϝʔδ ϨΠϠʔͷੵΈॏͶͰ ࡞ΒΕΔ
ϨΠϠʔ͕࡞ΒΕΔͷ COPY/ADD, RUN ͷλΠϛϯά
ϕʔεΠϝʔδ
ϕʔεΠϝʔδ $01:"%%
ϕʔεΠϝʔδ $01:"%% ϕʔεΠϝʔδ 36/
ϕʔεΠϝʔδ $01:"%% ϕʔεΠϝʔδ 36/ $01:"%%
ϕʔεΠϝʔδ $01:"%% ϕʔεΠϝʔδ 36/ $01:"%% 36/
36/ tar app/testdata app/.wh.large_file app/a.txt app/b.txt
ϨΠϠʔ ࠩͷϑΝΠϧΛ࣋ͭtar
আ.wh.͔Β࢝·Δ whiteoutϑΝΠϧΛ࡞Δ͚ͩ
ίϚϯυΛލ͍Ͱআͯ͠ Γଓ͚Δ
ϨΠϠʔ ͷࢀরΛ͚ͩΛ࣋ͭ
୯ҰΠϝʔδͷ߹
ϕʔεΠϝʔδ $01:"%% ϕʔεΠϝʔδ 36/ $01:"%% 36/
ෳΠϝʔδͷ߹
ϕʔεΠϝʔδ $01:"%% ϕʔεΠϝʔδ 36/ $01:"%% 36/ $01:"%% 36/ $01:"%%
Build Cache ͷ ϝΧχζϜ
ϕʔεΠϝʔδ $01:"%% ϕʔεΠϝʔδ 36/ $01:"%% 36/ $01:"%% 36/ $01:"%% ίϐʔͨ͠༰Ͱ
ίϚϯυ͕มΘΔ
ϕʔεΠϝʔδ $01:"%% ϕʔεΠϝʔδ 36/ $01:"%% 36/ $01:"%% 36/ $01:"%% ίϐʔͨ͠༰Ͱ
ίϚϯυ͕มΘΔ ڞ௨ͷΛ࣋ͭಉ͡ίϚϯυͷΠϝʔδͰ ࠷৽ͷͷΛΩϟογϡͱͯ͠༻͍Δ
ϕʔεΠϝʔδ $01:"%% ϕʔεΠϝʔδ 36/ $01:"%% 36/ $01:"%% 36/ $01:"%% ίϐʔͨ͠༰Ͱ
ίϚϯυ͕มΘΔ ڞ௨ͷΛ࣋ͭಉ͡ίϚϯυͷΠϝʔδͰ ࠷৽ͷͷΛΩϟογϡͱͯ͠༻͍Δ Dockerd
άϥϑͱͯ͠ ঢ়ଶΛ͍࣋ͬͯΔͷ dockerd
Agenda • docker buildͷ • CI ʹ͓͚Δdocker build • docker
buildʹඞཁͩͬͨͷ
CI্Ͱdocker build cache͕ޮ͔ͳ͍
ͳͥͳΒ dockerd͕ͣͬͱੜ͖͍ͯΔ Θ͚Ͱͳ͍͔Β
ڞ௨ͷΛ࣋ͭ ΠϝʔδͳͲ͍ͳ͍
ղܾࡦ
docker pullͯ͘͠Δ
લʹbuildͨ͠ ΠϝʔδΛpull͓͚ͯ͠ cache͕ޮ͘?
͍͍͑
֎෦͔Β͖࣋ͬͯͨΠϝʔδ —cache-from͕ͳ͍ͱର֎
͜ΕͰղܾʂ
ͦΜͳ͕࣌͋Γ·ͨ͠
ࠓ େmulti stage build࣌
աڈͷৗࣝ (෦తʹ)௨༻͠ͳ͍
εςʔδ͝ͱʹ Πϝʔδ͕࡞ΒΕΔ
Dockerfile Stage 1 Stage 2 Stage 3
ҰͷbuildͰ࡞ΕΔͷ 1Πϝʔδ͚ͩ
Dockerfile Stage 1 Stage 2 Stage 3 —target
cacheͷ࠷খ୯Ґ͕ Πϝʔδ
ಛఆͷεςʔδΛ cacheΛޮ͔ͤͯbuild͢Δ ͨΊʹ Ҏલͷεςʔδ͕શͯඞཁ
શ෦pull શ෦cache-from
docker pull application:build-base-cache || true docker build -t application:build-base-cache --target=build-base
--cache- from=application:build-base-cache . docker pull application:base-cache || true docker build -t application:base-cache --target=base --cache-from=application:build-base- cache,application:base-cache . docker pull application:app-build-cache || true docker build -t application:app-build-cache --target=app-build --cache- from=application:build-base-cache,application:base-cache,application:app-build-cache . docker pull application:app-base-cache || true docker build -t application:app-base-cache --target=app-base --cache- from=application:build-base-cache,application:base-cache,application:app-build- cache,application:app-base-cache . docker pull application:application-cache || true docker build -t application:application-cache --target=application --cache- from=application:build-base-cache,application:base-cache,application:app-build- cache,application:app-base-cache,application:application-cache .
߇͑Ίʹ͍ͬͯ ࠈ
Agenda • docker buildͷ • CI ʹ͓͚Δdocker build • docker
buildʹඞཁͩͬͨͷ
ඞཁͩͬͨͷͳʹ͔
docker buildҎ֎ͷ πʔϧΛݟͯΈΔ
uber/makisuͷ
makisu Uber͕࡞ͬͨbuilder
https://eng.uber.com/makisu/
2015͘Β͍͔Β DockerҠߦΛ࢝ΊͨUber
Apache MesosͱK8S
400αʔϏε͘Β͍
docker buildͷprocess ࣗಈԽ, ඪ४Խ
ػີใͷऔѻʹ·ͣࠔͬͨ
docker-squashͰղܾʂ
͔͠͠ build͕࣌ؒ2ഒʹ
͍ʹͳΒͳ͍ͷͰ dockerΛfork͢Δ͜ͱʹ
build࣌ʹ volumeΛmountͰ͖ΔΑ͏ʹ
େຬ
2017 3000αʔϏε·Ͱ
buildʹ2͔͔࣌ؒΓ 10GBΛ͑ΔΠϝʔδ
storage, ଳҬ, ੜ࢈ੑʹ μϝʔδ
εέʔϧ͢Δ ࣍ੈͷϏϧυʹ͍ͭͯߟ͑Δ
ϙʔλϒϧ ࢄΩϟογϡ αΠζ࠷దԽ
ϙʔλϒϧ ࢄΩϟογϡ αΠζ࠷దԽ
2017ʹ ࣗಈԽ͞Ε, εέʔϥϒϧͰ ޮతͳΠϯϑϥ͕͋ͬͨ
Docker build ͦͷ্Ͱಈ͔͔ͨͬͨ͠
docker build copy-on-writeͰࠩΛ ͍Ζ͍Ζ͍ͬͯΔͷͰ ڧ͍ݖݶ͕ඞཁ
ڧ͍ΫϥελͰ ηΩϡϦςΟ ճආ͍ͨ͠
ϙʔλϒϧ ࢄΩϟογϡ αΠζ࠷దԽ
LayerCacheͰ લճͷLayerΛ͍ճͤΔͱ build࣌ؒΛ͘Ͱ͖Δ
Dockerͷcache ϒϥϯνؒผαʔϏεͩͱ ޮ͔ͳ͍
build machineͷׂͰ cache hitΛ্͕ͤͨ͞ ෳࡶ্͕͕ͬͯ͠·ͬͨ
ϙʔλϒϧ ࢄΩϟογϡ αΠζ࠷దԽ
খ͍͞Πϝʔδ ࠷ߴ
storage network decompress ʹޮ͘
multi stage build ྑ͍ղܾࡦ
͔͠͠ Dockerfile͕ෳࡶʹͳΔ
ͦͷ΄͔ʹ layerΛ·͍ͨͰআ͍ͯ͠Δ ΠϝʔδͳͲ͋ͬͨ
makisu 3ͭͷΛղܾ͢Δ
ϙʔλϒϧ ࢄΩϟογϡ αΠζ࠷దԽ
ϙʔλϒϧ ࢄΩϟογϡ αΠζ࠷దԽ
makisu copy on writeΛΘͣ In Memory FSͰࠩΛऔΔ ৄ͘͠ޙड़
ऄ
Dockerlayerͷѹॖʹ GoͷgzipΛ͍ͬͯΔ͕ pgzipͷ΄͏͕͍ͷͰ makisuͦͬͪ
ϙʔλϒϧ ࢄΩϟογϡ αΠζ࠷దԽ
Redis(or FS or HTTP)ʹ digestͱRegistryͷ ώϞ͕͋Γ Cache͕ղܾ͞ΕΔ
ϙʔλϒϧ ࢄΩϟογϡ αΠζ࠷దԽ
ಠࣗͷDockerfile parserΛ ͬͯ ໌ࣔతʹϨΠϠʔΛ࡞Δ ػߏ͕͋Δ
Stage FROM image [AS stage] RUN apk add ca-certificates COPY
package.json . COPY package-lock.json . ENV NODE_ENV=production RUN npm ci #!COMMIT COPY . . RUN npm run build
Stage FROM image [AS stage] RUN apk add ca-certificates COPY
package.json . COPY package-lock.json . ENV NODE_ENV=production RUN npm ci #!COMMIT COPY . . RUN npm run build
͜ͷػߏ͕͋ΕػີใΛ COPYͨ͋͠ͱʹআͯ͠ COMMITΛ͢Δͱ͍͏ࣄ͕ Dockerfile͚ͩͰ࣮ݱՄೳ
kaniko
kaniko Google͕࡞ͬͨbuilder
ίϯςφ্Ͱಈ͘
͜Ε·Ͱίϯςφ্Ͱͷ buildͬͯͲ͏ͯͨ͠ͷʁ
Privileged Container EPDLFSDMJ EPDLFSE HTTP
Container EPDLFSDMJ EPDLFSE HTTP Host
Container EPDLFSDMJ EPDLFSE HTTP Remote
kaniko
Container LBOJLP SPPUGT
Container LBOJLP SPPUGT 4($4 State &$3($3 Layer Cache
Container LBOJLP SPPUGT 4($4 State &$3($3 Layer Cache exec
Container LBOJLP SPPUGT 4($4 State &$3($3 Layer Cache exec snapshot
Container LBOJLP SPPUGT 4($4 State &$3($3 Layer Cache exec snapshot
Container LBOJLP 4($4 State &$3($3 SPPUGT &$3($3 Layer Cache Image
exec snapshot Registry
ঢ়ଶΛ ίϯςφ෦ʹ࣋ͨͳ͍
Image୯ҐͰͷ Pull/CacheͰͳ͘ Layer୯Ґ
BuildͱCacheͷߋ৽͕ ಉ࣌ʹߦΘΕΔ
Multi Stage Build ͰCache͕ޮ͘
ImageઈରPush͢Δ
ίϯςφΛͬͨ Build/Pushʹద͍ͯ͠Δ
kanikoʹ͍ͭͯৄ͘͠ kaniko ͕ԿΛ͍ͯ͠Δ͔, Կ͕Ͱ͖Δ͔ https://orisano.hatenablog.com/entry/2019/05/20/120032
makisuͱkaniko جຊతʹಉ͡࡞Γ
kaniko ͷ΄͏͕ Redisͱ͔͍Βͳ͍ͷͰ ͍͍͢
kaniko͓͢͢ΊͰ͢
Dockerfileͷ͜ͱ Docker buildͷ͜ͱͰ ࠔͬͨΒؾܰʹ twitter: @orisano