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.3k
Better docker image+
orisano
6
6.6k
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
どこまでゆるくて許されるのか
tk3fftk
0
510
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
3
1.6k
5分で問診!Composer セキュリティ健康診断
codmoninc
0
470
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
200
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
160
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
180
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
2.9k
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
500
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
410
ローカルLLMでどこまでコードが書けるか -縮小版 / How much code can be written on a local LLM Shortened
kishida
2
200
act1-costs.pdf
sumedhbala
0
240
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
Featured
See All Featured
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
220
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
190
How to train your dragon (web standard)
notwaldorf
97
6.7k
It's Worth the Effort
3n
188
29k
Faster Mobile Websites
deanohume
310
32k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.4k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
New Earth Scene 8
popppiees
3
2.4k
Making Projects Easy
brettharned
120
6.7k
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