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
技術的負債解消で開発者の未来を開く- AIの力でコード刷新
kmd2kmd
0
120
AIで効率化できた業務・日常
ochtum
0
150
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
1
570
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.6k
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
810
OSもどきOS
arkw
0
600
Oxcを導入して開発体験が向上した話
yug1224
4
350
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
200
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
250
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
360
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
220
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
990
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
55
10k
Speed Design
sergeychernyshev
33
1.9k
What's in a price? How to price your products and services
michaelherold
247
13k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.6k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
220
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
740
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
200
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
2
270
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
The Curious Case for Waylosing
cassininazir
1
410
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
240
ラッコキーワード サービス紹介資料
rakko
1
3.8M
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