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
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
250
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.5k
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
180
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
360
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
3.8k
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
210
Claude Team Plan導入・ガイド
tk3fftk
0
250
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
660
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
550
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
450
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
2.8k
php-fpmのプロセスが枯渇した日-調査・対処・そして本当にやるべきだったこと-
shibuchaaaan
0
210
Featured
See All Featured
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
240
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
610
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
440
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Visualization
eitanlees
152
17k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
200
How to Talk to Developers About Accessibility
jct
2
480
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
410
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
450
For a Future-Friendly Web
brad_frost
183
10k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Writing Fast Ruby
sferik
630
63k
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