Better Docker Image
by
Recruit Technologies
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Better Docker Image Container Build Meetup #1 #container_build @orisano
Slide 2
Slide 2 text
ྑ͍Docker ImageͱԿ͔
Slide 3
Slide 3 text
αʔϏεʹؔΘΔਓΛ ͤʹ͢ΔΠϝʔδ
Slide 4
Slide 4 text
ݟͯΘ͔Γ͍͢ खݩͰߴʹbuild͞ΕΔ CI্Ͱߴʹbuild͞ΕΔ ߴʹdeploy͞ΕΔ
Slide 5
Slide 5 text
ࠓ͍ͨ͜͠ͱ
Slide 6
Slide 6 text
ͲͷΑ͏ʹ͘͢Δ͔ ͲͷΑ͏ʹখ͘͢͞Δ͔
Slide 7
Slide 7 text
ͲͷΑ͏ʹ͘͢Δ͔ ͲͷΑ͏ʹখ͘͢͞Δ͔
Slide 8
Slide 8 text
ͲͷΑ͏ʹ͘͢Δ͔ • ΠϝʔδΛখ͘͢͞Δ • ίϚϯυͦͷͷΛ͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ • ඞཁͳ͍εςʔδΛbuild͠ͳ͍
Slide 9
Slide 9 text
ͲͷΑ͏ʹ͘͢Δ͔ • ΠϝʔδΛখ͘͢͞Δ • ίϚϯυͦͷͷΛ͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ • ඞཁͳ͍εςʔδΛbuild͠ͳ͍
Slide 10
Slide 10 text
imageΛখ͘͢͞Δͷ docker push͢Δͱ͖ͷ docker pull͢Δͱ͖ͷ ͷߴԽʹͭͳ͕Δ
Slide 11
Slide 11 text
Ͳͷ༷ʹখ͘͢͞Δ͔ ͋ͱͰ
Slide 12
Slide 12 text
ͲͷΑ͏ʹ͘͢Δ͔ • ΠϝʔδΛখ͘͢͞Δ • ίϚϯυͦͷͷΛ͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ • ඞཁͳ͍εςʔδΛbuild͠ͳ͍
Slide 13
Slide 13 text
ίϚϯυͦͷͷΛ͘͢Δ
Slide 14
Slide 14 text
URLʹର͢ΔADDΛΘͳ͍ RUNͷதΛ͘͢Δ
Slide 15
Slide 15 text
URLʹର͢ΔADDΛΘͳ͍ RUNͷதΛ͘͢Δ
Slide 16
Slide 16 text
URLʹର͢ΔADD جຊతʹμϯϩʔυ͢Δ
Slide 17
Slide 17 text
͍
Slide 18
Slide 18 text
ΞΫηε͍ͯ͠Δઌͷ ίϯςϯπ͕ႈͳΒ wget + gzip + tarͰे
Slide 19
Slide 19 text
`RUN wget`ʹ͢Δ͜ͱͰ cache͕ޮ͘
Slide 20
Slide 20 text
ႈͰͳ͍Ϧιʔεʹ ґଘ͢ΔͷΛۃྗΊΔ
Slide 21
Slide 21 text
URLʹର͢ΔADDΛΘͳ͍ RUNͷதΛ͘͢Δ
Slide 22
Slide 22 text
GitHub͔Β࣮ߦϑΝΠϧΛ curl or wgetͰऔಘ͢Δ ͕͍
Slide 23
Slide 23 text
Ͳ͏ʹ͔͘Ͱ͖ͳ͍͔ curl -vvvΛ͏ͬͯΈͨ
Slide 24
Slide 24 text
GitHub ReleaseS3Ͱ͋Δ S3Accept-Ranges: bytes ͱ͍͏͜ͱ͕Θ͔ͬͨ
Slide 25
Slide 25 text
Accept-Ranges: bytes ͬͯͳΜͩΖ͏
Slide 26
Slide 26 text
RFC7233, Range Requests ൣғΛࢦఆͯ͠ downloadͰ͖Δ
Slide 27
Slide 27 text
ͭ·Γ ฒྻμϯϩʔυ͕Մೳ
Slide 28
Slide 28 text
github.com/orisano/rget
Slide 29
Slide 29 text
No content
Slide 30
Slide 30 text
ڥʹΑΓ·͕͢ 5min -> 2min
Slide 31
Slide 31 text
DockerfileͷҎ֎ʹ ͘͢ΔΞϓϩʔν͋Δ
Slide 32
Slide 32 text
ͲͷΑ͏ʹ͘͢Δ͔ • ΠϝʔδΛখ͘͢͞Δ • ίϚϯυͦͷͷΛ͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ • ඞཁͳ͍εςʔδΛbuild͠ͳ͍
Slide 33
Slide 33 text
cacheΛޮ͔ͤΔ
Slide 34
Slide 34 text
docker build͢ΔϚγϯ͕ ಉҰͷ߹ ಉҰͰͳ͍߹
Slide 35
Slide 35 text
docker build͢ΔϚγϯ͕ ಉҰͷ߹ ಉҰͰͳ͍߹
Slide 36
Slide 36 text
cacheͷΈΛཧղ͢Δ
Slide 37
Slide 37 text
RUN จࣈྻ͕มΘΒͳ͍ݶΓ جຊతʹcache͞ΕΔ
Slide 38
Slide 38 text
COPY, ADD͢ΔϑΝΠϧͷ ༰͕มΘͬͨ߹ Ҏ߱ͷRUNͷcache͕ഁغ
Slide 39
Slide 39 text
ͳͷͰ lockfileͳͲΛઌʹίϐʔͯ͠ install͚ͩͯ͠cacheͤ͞Δ
Slide 40
Slide 40 text
No content
Slide 41
Slide 41 text
No content
Slide 42
Slide 42 text
docker build͢ΔϚγϯ͕ ಉҰͷ߹ ಉҰͰͳ͍߹
Slide 43
Slide 43 text
CI্Ͱbuild͢Δͱ͖ͳͲ cache͕ͳ͍͜ͱ͕ଟ͍
Slide 44
Slide 44 text
docker save & load or docker pull docker build —cache-from Λ͏
Slide 45
Slide 45 text
image͕େ͖͍/layer͕ଟ͍ ߹ buildͷ΄͏͕ૣ͍͜ͱ͋Δ
Slide 46
Slide 46 text
image͕େ͖͍/layer͕ଟ͍ ߹ buildͷ΄͏͕ૣ͍͜ͱ͋Δ ܭଌܾͯ͠ΊΔ
Slide 47
Slide 47 text
ͲͷΑ͏ʹ͘͢Δ͔ • ΠϝʔδΛখ͘͢͞Δ • ίϚϯυͦͷͷΛ͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ • ඞཁͳ͍εςʔδΛbuild͠ͳ͍
Slide 48
Slide 48 text
ґଘͷͳ͍εςʔδΛ ฒྻͰ࣮ߦ͢Δ
Slide 49
Slide 49 text
buildkitΛ͍ͬͯͩ͘͞ʂ github.com/moby/buildkit export DOCKER_BUILDKIT=1
Slide 50
Slide 50 text
ͲͷΑ͏ʹ͘͢Δ͔ • ΠϝʔδΛখ͘͢͞Δ • ίϚϯυͦͷͷΛ͘͢Δ • cacheΛޮ͔ͤΔ • ґଘͷͳ͍εςʔδΛฒྻͰ࣮ߦ͢Δ • ඞཁͳ͍εςʔδΛbuild͠ͳ͍
Slide 51
Slide 51 text
ඞཁͳ͍εςʔδΛ build͠ͳ͍
Slide 52
Slide 52 text
—targetΛ͑Α͍ͷͰʁ
Slide 53
Slide 53 text
—target ࢦఆͨ͠εςʔδҎલΛ શ෦build͢Δ
Slide 54
Slide 54 text
multi stage buildΛ ౿ΈࠐΜ͍ͩํ͍ͯ͠Δͱ ૺ۰͕ͪ͠
Slide 55
Slide 55 text
͓ͦΒ͘buildkitͰͰ͖Δ͕ buildkit͕͑ͳ͍߹ʹ
Slide 56
Slide 56 text
github.com/orisano/targd • DockerfileͷASTΛऔಘ • ࢦఆ͞ΕͨεςʔδͷґଘεςʔδΛநग़ • ґଘεςʔδ͚ͩͷDockerfileΛग़ྗ
Slide 57
Slide 57 text
github.com/orisano/targd
Slide 58
Slide 58 text
ͲͷΑ͏ʹ͘͢Δ͔ ͲͷΑ͏ʹখ͘͢͞Δ͔
Slide 59
Slide 59 text
ͲͷΑ͏ʹখ͘͢͞Δ͔ • multi stage buildΛ͏ • RUNΛ·ͱΊΔ(?) • ͳͥେ͖͍͔ΛΔ
Slide 60
Slide 60 text
ͲͷΑ͏ʹখ͘͢͞Δ͔ • multi stage buildΛ͏ • RUNΛ·ͱΊΔ(?) • ͳͥେ͖͍͔ΛΔ
Slide 61
Slide 61 text
multi stage buildΛ͏
Slide 62
Slide 62 text
multi stage buildͰ ͋Γ͕ͪͳٙ
Slide 63
Slide 63 text
࠷ऴతͳΠϝʔδ͕ খ͘͞ͳΔ͔Β ͦΕ·Ͱͷεςʔδ ࠷దԽ͠ͳͯ͘ྑ͍ʁ
Slide 64
Slide 64 text
No content
Slide 65
Slide 65 text
ݸਓతʹNo
Slide 66
Slide 66 text
moby/issues/34715 —cache-formͩͱ multi stage buildͷ લஈͷεςʔδͷcache͕ ޮ͔ͳ͍
Slide 67
Slide 67 text
࠷ऴεςʔδ͔͠ pushͯ͠ͳ͍͔ΒͨΓલ
Slide 68
Slide 68 text
CI্Ͱͷbuild —cache-fromΛ͏ ࠷ऴεςʔδ͚ͩcache͢Δ ҙຯͳ͍
Slide 69
Slide 69 text
multi stage build࣌ʹ cacheΛޮ͔͍ͤͨ߹ લͷεςʔδ ໌ࣔతʹpush͢Δ͔͠ͳ͍
Slide 70
Slide 70 text
݁ہpush͢ΔͷͰ push/pullͷίετ͕͔͔Δ ͯ͢ͷεςʔδΛฏʹ খ͖͘͢͞ (ݸਓͷݟղͰ͢)
Slide 71
Slide 71 text
ͲͷΑ͏ʹখ͘͢͞Δ͔ • multi stage buildΛ͏ • RUNΛ·ͱΊΔ(?) • ͳͥେ͖͍͔ΛΔ
Slide 72
Slide 72 text
RUNΛ·ͱΊΔ(?)
Slide 73
Slide 73 text
Ͳ͔ͬʔ;͍͊Δ 1ͭͷRUNʹ શ෦ॻ͘ͱྑ͍Β͍͠(?)
Slide 74
Slide 74 text
github.com/orisano/minid • DockerfileͷASTΛऔಘ • ࿈ଓ͢ΔRUN, COPY, ADDΛ࿈݁͢Δ • ݁ՌͷDockerfileΛग़ྗ
Slide 75
Slide 75 text
github.com/orisano/minid
Slide 76
Slide 76 text
αΠζ͕খ͘͞ͳͬͨ
Slide 77
Slide 77 text
ͰͳΜͰʁ
Slide 78
Slide 78 text
ϨΠϠʔͷΦʔόʔϔου͕ ݮΔ͔Βখ͘͞ͳΔʁ
Slide 79
Slide 79 text
͍͍͑
Slide 80
Slide 80 text
·ͣ Ͳ͏͍͏ܗͰอଘ͞ΕͯΔ͔ ΛΔ
Slide 81
Slide 81 text
moby/image/spec/v1.md
Slide 82
Slide 82 text
AUFS
Slide 83
Slide 83 text
http://docs.docker.jp/engine/userguide/storagedriver/aufs-driver.html
Slide 84
Slide 84 text
আ whiteoutϑΝΠϧͷՃ Ҡಈ opaqueϑΝΠϧͷՃ ʴ ҠಈઌͷϑΝΠϧࠩ
Slide 85
Slide 85 text
ҰͰ RUN,COPY,ADDΛލ͙ͱ imageʹͬͯ͠·͏
Slide 86
Slide 86 text
ػցతʹͰ ҰͭͷRUNʹ·ͱΊΔ͜ͱͰ ༨ܭͳͷΛݮͰ͖Δ
Slide 87
Slide 87 text
1ͭͷϨΠϠʔʹ ·ͱΊΔ͜ͱ ຊʹਖ਼͍͠ͷ͔
Slide 88
Slide 88 text
ϨΠϠʔΛผ͚Δ͜ͱʹΑΓ ฒྻμϯϩʔυͷԸܙ cacheͷ༗ޮ׆༻ Մಡੑͷ্
Slide 89
Slide 89 text
ϨΠϠʔΛผ͚Δ͜ͱʹΑΓ ฒྻμϯϩʔυͷԸܙ cacheͷ༗ޮ׆༻ Մಡੑͷ্ ܭଌܾͯ͠ΊΔ
Slide 90
Slide 90 text
ͱ͍͑ ෳϨΠϠʔʹ ލ͕Βͳ͍ఔʹ ׂ͢Δͷ͕ྑͦ͞͏
Slide 91
Slide 91 text
ͲͷΑ͏ʹখ͘͢͞Δ͔ • multi stage buildΛ͏ • RUNΛ·ͱΊΔ(?) • ͳͥେ͖͍͔ΛΔ
Slide 92
Slide 92 text
ͳͥେ͖͍͔ΛΔ
Slide 93
Slide 93 text
͍͔ͳΔνϡʔχϯάͰ ܭଌͤͣʹ͍͚ͬͯͳ͍
Slide 94
Slide 94 text
docker history
Slide 95
Slide 95 text
docker history
Slide 96
Slide 96 text
ͲͷϨΠϠʔ͕ େ͖͍͔Θ͔Δ͚Ͳ ͳͥେ͖͍͔͔ΓͮΒ͍
Slide 97
Slide 97 text
ҙ֎ʹίϚϯυ͕ Ͳ͏͍͏ϑΝΠϧΛ࡞Δͷ͔ Βͳ͍
Slide 98
Slide 98 text
github.com/orisano/dlayer • docker saveͰಘΒΕͨtarΛղੳ • layerͱcmdͷରԠΛͱΔ • layerͷࠩΛϑΝΠϧαΠζ͕େ͖͍ॱʹද ࣔ
Slide 99
Slide 99 text
github.com/orisano/dlayer
Slide 100
Slide 100 text
࣮ࡍʹdlayerΛͬͯ golangެࣜalpineΠϝʔδͷ αΠζΛݮΒͯ͠Έͨ
Slide 101
Slide 101 text
docker-library/golang/pull/232
Slide 102
Slide 102 text
No content
Slide 103
Slide 103 text
golang:1.11͔Βtoolchainͷ αΠζ͕Ͱ͔͘ͳͬͨ SSAͰͷ࠷దԽ͕૿͔͑ͨΒʁ
Slide 104
Slide 104 text
1.10: 253MB
Slide 105
Slide 105 text
1.11: 305MB
Slide 106
Slide 106 text
࡞ͬͨπʔϧ • github.com/orisano/rget • github.com/orisano/targd • github.com/orisano/minid • github.com/orisano/dlayer • ྑ͍ͱࢥͬͨΒελʔ͍͚ͯͨͩ͠ΔͱྭΈʹͳΓ·͢
Slide 107
Slide 107 text
·ͱΊ • ίϚϯυΛ͘Ͱ͖ͳ͍͔ߟ͑Δ • cacheΛཧղͯ͠༗ޮʹ׆͔͢ (CI or ϩʔΧϧ) • multi stage buildΛ͏ (ॏ͍stageΛcache͢Δ) • layerΛখ͘͢͞ΔͨΊʹੳ͢Δ • buildkitΛ͏!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Slide 108
Slide 108 text
rget͜΅Ε
Slide 109
Slide 109 text
github.com/orisano/rget
Slide 110
Slide 110 text
Ͱ ͜ΕͰຊʹ͍͍ΜͩΖ͏͔
Slide 111
Slide 111 text
rgetͷbinaryΛdownload ͢ΔͷͰෛ͚ͨؾ͕͢Δ()
Slide 112
Slide 112 text
shell͚ͩͰ ࣮ݱͰ͖ͳ͍ͩΖ͏͔
Slide 113
Slide 113 text
ϙʔλϒϧੑ͍Βͳ͍ͷͰ ओઓͷalpineʹߜΔ
Slide 114
Slide 114 text
alpine(busybox) xargs͕ೖ͍ͬͯΔʂʂʂ
Slide 115
Slide 115 text
xargsΛ͏͜ͱͰ ฒྻԽ ಉ࣌ଓ੍ݶ ͕࣮ݱͰ͖Δ
Slide 116
Slide 116 text
GitHub Release ؆୯ʹHEAD͕Ͱ͖ͳ͍ͷͰ GETͰbodyΛແࢹͯ͠ Content-LengthΛऔಘͰ͖Δ
Slide 117
Slide 117 text
seqͰ chunkͷrangeΛੜͰ͖Δ
Slide 118
Slide 118 text
wget206 Partial Content ͕͏·͘ѻ͑ͳ͍ͷͰμϝ
Slide 119
Slide 119 text
ํͳ͍ͷͰ curl -RͰdownload
Slide 120
Slide 120 text
࠷ޙʹcatͯ͠chunkΛ݁߹
Slide 121
Slide 121 text
shellͰ࣮ݱͰ͖Δʂ
Slide 122
Slide 122 text
͔͠͠ curlalpineඪ४Ͱͳ͍
Slide 123
Slide 123 text
apk add —no-cache curl ෛ͚ͨؾ͕͢Δ()
Slide 124
Slide 124 text
͔͠͠ wget206͕ॲཧͰ͖ͳ͍
Slide 125
Slide 125 text
ఘΊΒΕͳ͍ͷͰ busyboxͷwgetͷ ιʔείʔυΛಡΉ
Slide 126
Slide 126 text
busybox/networking/wget.c
Slide 127
Slide 127 text
busybox/networking/wget.c
Slide 128
Slide 128 text
-OͰࢦఆͨ͠ϑΝΠϧ͕ଘࡏ (ϑΝΠϧαΠζ͕1Ҏ্) -cΛࢦఆ͍ͯ͠Δ ্هͷ݅Λຬͨ͢ͱ͖ 206Λॲཧͯ͘͠ΕΔ
Slide 129
Slide 129 text
ͭ·Γ దͳ1byteͷϑΝΠϧʹ -cͰࢦఆ͢Δ͜ͱͰճආՄೳ
Slide 130
Slide 130 text
ઌ಄ͷ1byteΛऔΓআ͚Ε alpineඪ४ͷΈͰ࣮ݱՄೳ
Slide 131
Slide 131 text
tailͰՄೳ͕͍ͩ dd skip=1 iflag=skip_bytes ͕ߴ
Slide 132
Slide 132 text
alpineඪ४ͷΈͰ࣮ݱ
Slide 133
Slide 133 text
https://github.com/orisano/rget/blob/master/rget.sh