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 Release͸S3Ͱ͋Δ S3͸Accept-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

wget͸206 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

͔͠͠ curl͸alpineඪ४Ͱ͸ͳ͍

Slide 123

Slide 123 text

apk add —no-cache curl ͸ෛ͚ͨؾ͕͢Δ()

Slide 124

Slide 124 text

͔͠͠ wget͸206͕ॲཧͰ͖ͳ͍

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