Docker 18.09 æ°æ©è½ (ã¤ã¡ã¼ã¸ãã«ã&ã»ãã¥ãªãã£)
NTTã®é ç°ã§ãï¼Moby (âDocker)ï¼BuildKitï¼containerdãªã©ï¼ã³ã³ããé¢é£ã®ãªã¼ãã³ã½ã¼ã¹ã½ããã¦ã§ã¢ã®ã¡ã³ãã (éçºå§å¡ï¼ã³ããã¿ã¨ãï¼)ãåãã¦ãã¾ãï¼
æ¬è¨äºã§ã¯ï¼2018å¹´11æ8æ¥ã«ãªãªã¼ã¹ãããDocker 18.09ã®æ°æ©è½ãç´¹ä»ãã¾ãï¼
BuildKitã®æ£å¼çµ±å
Dockerfileããã³ã³ããã¤ã¡ã¼ã¸ããã«ãããæ©è½ã§ããï¼docker build
ã®æ°ããããã¯ã¨ã³ãã¨ãã¦ï¼BuildKitãDocker 18.06ããå®é¨çã«æ¡ç¨ããã¦ãã¾ãããï¼Docker 18.09ã«ã¦ï¼æ£å¼ãªæ©è½ã«æ ¼ä¸ãããã¾ããï¼
BuildKitã¯ï¼é ç°ã2017å¹´4æã«ææ¡ãã docker build
並ååã®pull requestãå¥æ©ã¨ãã¦ï¼Docker社 Tõnis Tiigiæ°ã®ä¸»å°ã«ããï¼Mobyåä¸ã®ãªã¼ãã³ã½ã¼ã¹ããã¸ã§ã¯ãã¨ãã¦åå¹´å¤ã«çºè¶³ãã¾ããï¼ããã¸ã§ã¯ãçºè¶³æããï¼é ç°ãã¡ã³ããã¨ãã¦éçºã«åå ãã¦ãã¾ãï¼
BuildKitã¯ï¼Dockerfileã®åå½ä»¤éã®ä¾åæ§ãDAG (æåéå·¡åã°ã©ã)ã¨ãã¦è¡¨ç¾ãããã¨ã«ããï¼å½ä»¤ã®ä¸¦åå®è¡ãï¼æ£ç¢ºãªãã£ãã·ã¥å¤å®ãå®ç¾ãã¾ãï¼
ã¾ãï¼ãã«ãã³ã³ããã¹ãã®å·®å転éãªã©ã®æé©åããªããã¦ãã¾ãï¼
é«éåã®ç¨åº¦ã¯å ´åã«ããããã§ããï¼Dockerãç¨ãã¦Dockerèªä½(å³å¯ã«ã¯Moby)ããã«ããããã³ããã¼ã¯ã®å ´åï¼ç´2åéããªãã¨ã®å ±åããªããã¦ãã¾ãï¼
LLB
BuildKitã¯ï¼Dockerfileãã®ãã®ããã«ãããã®ã§ã¯ãªãï¼Dockerfileããã³ã³ãã¤ã«ãããä¸éè¨èªã§ããLLBããã«ããã¾ãï¼ (clangãCè¨èªãæ©æ¢°èªã«ç´æ¥ã³ã³ãã¤ã«ããã®ã§ã¯ãªãï¼LLVM IRãä»ããã®ã«ä¼¼ã¦ãã¾ãï¼)
LLBã¯ï¼Dockerfile以å¤ã®ã¤ã¡ã¼ã¸è¨è¿°è¨èªããã³ã³ãã¤ã«ãããã¨ãå¯è½ã§ãï¼ä¾ãã°ï¼HerokuãCloud Foundryã§ç¨ãããã¦ããï¼Buildpacksã®YAMLããLLBãã³ã³ãã¤ã«ãããã¨ãå¯è½ã§ãï¼YAMLã®1è¡ç®ã«shebangã®ããã« # syntax = tonistiigi/pack
ã¨è¨è¿°ãã¦ããã°ï¼ docker build
ã³ãã³ãããç´æ¥YAMLãæ±ããã¨ãã§ãã¾ãï¼
$ cat manifest.yaml
# syntax = tonistiigi/pack
---
applications:
- name: myapp
memory: 128MB
disk_quota: 256MB
random-route: true
buildpack: python_buildpack
command: python hello.py$ docker build âf manifest.yml
ãªãï¼ # syntax = ...
ã§æå®ããæååã¯ï¼Dockerã§äºç´ããã¦ããæååã§ã¯ãªãï¼LLBãåºåããããã°ã©ã (ããã³ãã¨ã³ã)ã®ã³ã³ããã¤ã¡ã¼ã¸ã®referenceæååã§ãï¼ã§ãã®ã§ï¼Dockerfileã§ãBuildpacksã§ããªãï¼ç¬èªã®ã¤ã¡ã¼ã¸è¨è¿°è¨èªã®ããã³ãã¨ã³ããã¦ã¼ã¶ãå®è£
ãï¼å©ç¨ãããã¨ãå¯è½ã§ãï¼
Cache Mount
å¾æ¥ã® docker build
ã§ã¯ï¼ã³ã³ãã¤ã©ãããã±ã¼ã¸ããã¼ã¸ã£ã®ãã£ãã·ã¥ãæå¹ã«æ´»ç¨ã§ãã¾ããã§ããï¼
ä¾ãã°ï¼æ¬¡ã®ãããªDockerfileãããã¨ãã¾ã:
FROM golang
...
RUN go build -o /foo ./pkg/foo
Goã®ã³ã³ãã¤ã©ã¯ãã£ãã·ã¥ãã³ã³ããå
ã® /root/.cache/go-build
ã«ä¿åãã¾ããï¼å¾æ¥ã® docker build
ã§ã¯ï¼Goã®ã½ã¼ã¹ãï¼Dockerfileã® RUN go build â¦
以åã®è¡ãæ¸ãæãããã³ã«ï¼ã³ã³ãã¤ã©ã®ãã£ãã·ã¥ãå«ãã¤ã¡ã¼ã¸ã¬ã¤ã¤ãç ´æ£ããªãã¦ã¯ãªãã¾ããã§ããï¼
BuildKitã§ã¯ï¼ RUN --mount=type=cache
å½ä»¤ãç¨ãããã¨ã§ï¼ãã£ãã·ã¥ãä¿æãããã¨ãã§ãã¾ãï¼ãã ãï¼ ä»ã®ã¨ããéæ¨æºå½ä»¤ã§ããããï¼Dockerfileã®1è¡ç®ã« # syntax = docker/dockerfile:experimental
ã¨è¨è¿°ããå¿
è¦ãããã¾ãï¼
# syntax = docker/dockerfile:experimental
FROM golang
...
RUN --mount=type=cache,target=/root/.cache/go-build \
go build -o /foo ./pkg/foo
RUN --mount=type=cache
å½ä»¤ããã¾ãæ´»ç¨ããã¨ï¼å¾æ¥ã® docker build
ãã33å以ä¸éããã«ããå¯è½ã§ãï¼
RUN --mount=type=cache
å½ä»¤ã¯ï¼ apt
ãªã©ã®ããã±ã¼ã¸ããã¼ã¸ã£ã®ãã£ãã·ã¥ã®ä¿æã«ãå©ç¨ãããã¨ãã§ãã¾ãï¼
# syntax = docker/dockerfile:experimental
FROM ubuntu
RUN rm -f /etc/apt/apt.conf.d/docker-clean; \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > \
/etc/apt/apt.conf.d/keep-cache
RUN \
--mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt \
apt update && apt install -y gcc
Secret Mount
å¾æ¥ã® docker build
ã§ã¯ï¼Dockerfileã®ä¸ããï¼ãã©ã¤ãã¼ããªGitãªãã¸ããªãï¼S3ãªã©ã¸ã¢ã¯ã»ã¹ãããã¨ããå°é£ã§ããï¼
éµãã¡ã¤ã«ã COPY
( ADD
)ããã°ããã ãã®ããã«æãããããç¥ãã¾ãããï¼ãã®ãããªæ¹æ³ã¯å±éºã§ãï¼éµã®ãã¡ã¤ã«ãå¾ã§ RUN rm
ãã¦ãï¼ COPY
å½ä»¤ã«å¯¾å¿ããã¤ã¡ã¼ã¸ã¬ã¤ã¤ã®tarã®ä¸ã«ã¯ï¼éµãã¡ã¤ã«ãæ®ãããã§ãï¼éµãã¡ã¤ã«ãå«ãã¤ã¡ã¼ã¸ãï¼ä¸ç¹å®å¤æ°ã®ã¦ã¼ã¶ãåç
§å¯è½ãªã¬ã¸ã¹ããªã«pushããã¨ï¼GitãS3ãªã©ã®ã¢ã¯ã»ã¹æ¨©éã奪åãããæããããã¾ãï¼
COPY
ããéµãã¡ã¤ã«ãã¤ã¡ã¼ã¸ã«æ®åãããã¨ãé²ãã«ã¯ï¼ãã«ãã¹ãã¼ã¸ãã«ããï¼ docker build --squash
ã注ææ·±ãç¨ããå¿
è¦ãããã¾ãï¼
BuildKitã§ã¯ï¼ RUN --mount=type=secret
å½ä»¤ãç¨ãããã¨ã§ï¼éµãã¡ã¤ã«ãã¤ã¡ã¼ã¸ã«æ®ããå®å
¨ã«ãã¦ã³ããããã¨ãã§ãã¾ãï¼
# syntax = docker/dockerfile:experimental
FROM ...
RUN --mount=type=secret,id=ssh,target=/root/.ssh/id_rsa git clone ...
ä¸ã®ä¾ã®Dockerfileã¯ï¼ docker build --secret id=ssh,src=$HOME/.ssh/id_rsa
ã®ããã«ï¼ä»»æã®éµãã¡ã¤ã«ãç´ä»ãã¦ãã«ããããã¨ãåºæ¥ã¾ãï¼
SSH Mount
ä¸è¨ã® RUN --mount=type=secret
å½ä»¤ã¯ï¼ãã¹ãã¬ã¼ãºä»ãã®SSHç§å¯éµã«ã¯åããªãåé¡ãããã¾ãï¼ ãã«ãã³ã³ããã«ã¯æ¨æºå
¥åãæ¥ç¶ãããï¼ãã¹ãã¬ã¼ãºãå
¥åã§ããªãããã§ãï¼
ãã¹ãã¬ã¼ãºä»ãã®SSHç§å¯éµã«ã¤ãã¦ã¯ï¼ä»£ããã« RUN --mount=type=ssh
å½ä»¤ã使ç¨ãããã¨ãã§ãã¾ãï¼
# syntax = docker/dockerfile:experimental
FROM ...
RUN --mount=type=ssh git clone ...
docker build
å®è¡åã« ssh-agent
ãèµ·åãããã¨ã§ï¼ãã¹ãã¬ã¼ãºãå
¥åãããã¨ãå¯è½ã§ãï¼
$ eval $(ssh-agent)
$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /home/penguin/.ssh/id_rsa: (ãã¹ãã¬ã¼ãºãå
¥å)
$ docker build --ssh default=$SSH_AUTH_SOCK .
BuildKitã®æå¹å
BuildKitãæå¹åããã«ã¯ï¼ docker build
ã³ãã³ãå®è¡åã«ç°å¢å¤æ°DOCKER_BUILDKIT=1
ãè¨å®ãã¦ããå¿
è¦ãããã¾ãï¼ãããã¯ï¼ /etc/docker/daemon.json
ã« {"features":{"buildkit":true}}
ã¨è¨è¿°ãã¦ãæå¹åã§ãã¾ãï¼
å³ã®éãï¼docker build
ã³ãã³ãã®åºåãå¾æ¥ã¨å¤§ããå¤ãã£ã¦ããã°ï¼BuildKitãæå¹ã«ãªã£ã¦ãã¾ãï¼
ãªã¢ã¼ãDockerãã¹ãã¸ã®SSHæ¥ç¶
docker
ã³ãã³ãã¯ï¼ãªã¢ã¼ãã®Dockerãã¹ãã«REST APIãç¨ãã¦æ¥ç¶ãããã¨ãåºæ¥ã¾ãï¼Dockerãã¹ããæ»æè
ã«ä¹ã£åããããã¨ãé²ãã«ã¯ï¼TLSãæå¹åãããï¼ãã¼ãã¸ã¢ã¯ã»ã¹å¯è½ãªIPã¢ãã¬ã¹ãçµã£ããããå¿
è¦ãããã¾ãï¼ããããªããï¼ããããè¨å®ã¯å®¹æã§ã¯ããã¾ããï¼å®éï¼Dockerãã¹ãã®è¨å®ä¸åãçªãã¦ä»®æ³é貨ãçºæãããã«ã¦ã§ã¢ã確èªããã¦ãã¾ãï¼
Docker 18.09ã§ã¯ï¼é ç°ã2017å¹´ããææ¡ãã¦ããï¼SSHãç¨ãããªã¢ã¼ãDockerãã¹ãæ¥ç¶æ©è½ãæ¡ç¨ããã¦ãã¾ãï¼SSHã¯ï¼ãªã¢ã¼ãã®Linuxãã¹ãã«æ¥ç¶ããæãä¸è¬çãªæ¹æ³ã§ããï¼TLSã«æ¯ã¹ã¦ç°¡åã«è¨å®ãããã¨ãåºæ¥ã¾ãï¼
ãã®æ©è½ã¯ï¼ç°å¢å¤æ° DOCKER_HOST=ssh://ã¦ã¼ã¶@ãã¹ã
ãè¨å®ããç¶æ
㧠docker
ã³ãã³ããå®è¡ããã¨å©ç¨ãããã¨ãåºæ¥ã¾ãï¼åã« ssh -l ã¦ã¼ã¶ ãã¹ã -- docker
ã³ãã³ããå®è¡ããå ´åã¨ç°ãªãï¼ã¯ã©ã¤ã¢ã³ãã® ~/.docker/config.json
ã«ä¿åããã¦ããã¬ã¸ã¹ããªèªè¨¼æ
å ±ãï¼ãã«ãã³ã³ããã¹ãã«ã¢ã¯ã»ã¹ãããã¨ãå¯è½ã§ãï¼
ãã®ä»ã®å¤æ´ç¹
Docker 18.09ããã¯ï¼ä»¥ä¸ã®ã¹ãã¬ã¼ã¸ãã©ã¤ããéæ¨å¥¨(deprecated)ã¨ãªã£ã¦ãã¾ã:
devicemapper
overlay
ãããã®ã¹ãã¬ã¼ã¸ãã©ã¤ãã¯ï¼å°æ¥ã®ãªãªã¼ã¹ã§ã¯åé¤ãããäºå®ã¨ãªã£ã¦ãã¾ãï¼ã¾ãï¼ aufs
ãã©ã¤ãã«ã¤ãã¦ãï¼Docker 19.03ãç®å¦ã«éæ¨å¥¨ã¨ãããã¨ãäºå®ããã¦ãã¾ãï¼ã¦ã¼ã¶ã¯ï¼å¯è½ãªéãæ©æã« overlay2
ãã©ã¤ããªã©ã«ä¹ãæãããã¨ãæ¨å¥¨ããã¦ãã¾ãï¼ overlay2
ãã©ã¤ãã¸ã®ä¹ãæãæ¹ã«ã¤ãã¦ã¯ Dockerã®ããã¥ã¡ã³ããã覧ãã ããï¼
ä»å¾ã®ãªãªã¼ã¹
Docker 17.03ãã18.06ã¾ã§ã¯edgeçãæ¯æï¼stableçã3ã¶ææ¯ã«ãªãªã¼ã¹ããã¦ãã¾ãããï¼18.09以éã¯ï¼6ã¶ææ¯ã®ãªãªã¼ã¹ãäºå®ããã¦ãã¾ãï¼
ä»å¾ã®ãªãªã¼ã¹ã¸åãï¼Dockerã»Mobyã³ãã¥ããã£ã§ã¯ä¸»ã«ä»¥ä¸ã®ä½æ¥ã«åãçµãã§ãã¾ã:
RUN --mount=type=cache
ãªã©ã®æ°Dockerfileå½ä»¤ã®æ£å¼æ¡ç¨- érootã¦ã¼ã¶ã§Docker daemonãå®è¡å¯è½ã¨ããæ©è½ (Rootless ã¢ã¼ã)
- containerdã¨ã®éè¤ã³ã¼ãã®é¤å»ï¼è»½éå
ãããã«
ç§ãã¡NTTã¯ï¼ãªã¼ãã³ã½ã¼ã¹ã³ãã¥ããã£ã§å ±ã«æ´»åãã仲éãåéãã¦ãã¾ãï¼ãã²å¼ç¤¾ ã½ããã¦ã§ã¢ã¤ããã¼ã·ã§ã³ã»ã³ã¿ç´¹ä»ãã¼ã¸åã³ï¼æ¡ç¨æ å ±ãã¼ã¸ãã覧ãã ããï¼