Dockerã¤ã¡ã¼ã¸åæãã¼ã«ãdiveããå©ç¨ãã¦Dockerã¤ã¡ã¼ã¸ã軽éåãã
ã¯ããã«
Docker ã¤ã¡ã¼ã¸ãµã¤ãºã¯å°ãããã°å°ããã»ã©ãPush 㨠Pull ã®é«éåã«ã¤ãªããå¬ããã§ãã
docker history
ã«ãã£ã¦ã¤ã¡ã¼ã¸ã¬ã¤ã¤ã¼ãã¨ã®ãµã¤ãºã¯åããã¾ãããã©ã®ã¬ã¤ã¤ã¼ã®ã©ã®ãã¡ã¤ã«ã®ãµã¤ãºã大ãããã¯åããã¾ããã
$ docker history maven:3-amazoncorretto-11 IMAGE CREATED CREATED BY SIZE COMMENT eb8a5bbcd061 12 days ago /bin/sh -c #(nop) CMD ["mvn"] 0B <missing> 12 days ago /bin/sh -c #(nop) ENTRYPOINT ["/usr/local/b⦠0B <missing> 12 days ago /bin/sh -c #(nop) COPY file:2bbb488dd73c55d6⦠327B <missing> 12 days ago /bin/sh -c #(nop) COPY file:1b3da5c58894f705⦠1.65kB <missing> 12 days ago /bin/sh -c #(nop) ENV MAVEN_CONFIG=/root/.m2 0B <missing> 12 days ago /bin/sh -c #(nop) ENV MAVEN_HOME=/usr/share⦠0B <missing> 12 days ago |4 BASE_URL=https://apache.osuosl.org/maven/⦠11.3MB <missing> 12 days ago |4 BASE_URL=https://apache.osuosl.org/maven/⦠200MB <missing> 12 days ago /bin/sh -c #(nop) ARG BASE_URL=https://apac⦠0B <missing> 12 days ago /bin/sh -c #(nop) ARG SHA=c35a1803a6e70a126⦠0B <missing> 12 days ago /bin/sh -c #(nop) ARG USER_HOME_DIR=/root 0B <missing> 12 days ago /bin/sh -c #(nop) ARG MAVEN_VERSION=3.6.3 0B <missing> 12 days ago /bin/sh -c #(nop) ENV JAVA_HOME=/usr/lib/jv⦠0B <missing> 12 days ago /bin/sh -c #(nop) ENV LANG=C.UTF-8 0B <missing> 12 days ago |1 version=11.0.8.10-1 /bin/sh -c set -eux ⦠279MB <missing> 12 days ago /bin/sh -c #(nop) ARG version=11.0.8.10-1 0B <missing> 3 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B <missing> 3 weeks ago /bin/sh -c #(nop) ADD file:788af9048b1c16334⦠163MB
dive
A tool for exploring a docker image, layer contents, and discovering ways to shrink the size of your Docker/OCI image.
ãã®ãã¼ã«ã§ã¯ãã¬ã¤ã¤ã¼ãã¨ã«ã©ã®ãã¡ã¤ã«ã追å ã»åé¤ãããã®ããã©ããããã®ãµã¤ãºãªã®ããåããã¾ãã Go ã§æ¸ããã¦ãã¦ã20000 ã¹ã¿ã¼ãããã¤ãã¦ãã¾ãã
ã¤ã³ã¹ãã¼ã«
# brewã§ã¤ã³ã¹ãã¼ã« $ brew install dive # go getã§ã¤ã³ã¹ãã¼ã« $ go get github.com/wagoodman/dive
Dockerã§ãå®è¡ã§ãããä»ã®ã¤ã³ã¹ãã¼ã«æ¹æ³ãREADMEã«æ¸ãã¦ããã¾ãã
使ãæ¹
# Analyze $ dive <your-image-tag> # Build & Analyze $ dive build -t <some-tag> .
以ä¸ã®ã³ãã³ãã§ãã¼ã«ãèµ·åãã¾ãã ã¿ã¼ããã«ä¸ã§ããããã§ããã®ãTUIã¨ããããã§ãã
dive ã§è»½éå
ä»åã¯ãmaven:3-amazoncorretto-11
ã軽éåãã¾ãã
dive ã®å®éã®ä½¿ãæ¹ãç´¹ä»ããªãã説æãã¾ãã
ã¾ããä¸ã®ãªãã¸ããªã®docker-maven/amazoncorretto-11/Dockerfile
ããã«ãããdive
ãèµ·åãã¾ãã
$ docker build -t before-maven-amazoncorretto-11 .
$ dive before-maven-amazoncorretto-11
ãããªãç»é¢ã«ãããã表示ããã¦æåã¯è¨³ãããããªãã¨æãã¾ãã
- ç»é¢å·¦ä¸
Layers
:ã©ã®ã¬ã¤ã¤ã¼ã¾ã§ã調æ»ãããé¸æ - ç»é¢å·¦ä¸
Layer Details
: ãã®ã¬ã¤ã¤ã¼ã§ãªã«ãå®è¡ãã¦ãããã表示 - ç»é¢å·¦ä¸
Image Details
: ã¤ã¡ã¼ã¸å ¨ä½ã®æ å ±ã表示 - ç»é¢å³
Current Layer Contents
:Layers
ã§æå®ããã¬ã¤ã¤ã¼ã«å«ã¾ãã¦ãããã¡ã¤ã«ããªã¼ããµã¤ãºã¨å ±ã«è¡¨ç¤º
Tab
ã§Layers
ã¨Current Layer Contents
ã移åããªãã使ãã¾ãã
æåã¯ãã£ã¬ã¯ããªãéããã¦ãã¦ç»é¢å³ã«ãã¡ã¤ã«ããããã表示ããã¦è¦ã¥ããã®ã§ãSpace
ã§ãã£ã¬ã¯ããªéãã¦ããã¾ãã
^Space
ã§ä¸æ°ã«éããããããã§ãããMac ã®ã·ã§ã¼ãã«ããã¨è¡çªãã¦ä½¿ãã¾ããã§ããã
è¦ããããªãã¾ããã
Layers
ã§ä¸ä¸ã«ç§»åããã¨ãããã«å¯¾å¿ãã¦Current Layer Contents
ãå¤åããã£ã¬ã¯ããªããã¡ã¤ãºã®ãµã¤ãºã®å¤åãåããã¾ãã
Layers
ã確èªããã¨ããµã¤ãºå¤§ããå¢ããããã«ããã¯ã¨ãªãããã¬ã¤ã¤ã¼ã¯ä¸ãã 3 ã¤ã¨åããã¾ãã
ä¸ãã1 çªç®ã¨ 2 çªç®ã®ã¬ã¤ã¤ã¼ã¯Amazon Linux ã®/usr
㨠amazoncorretto ã®/usr/lib/jvm
ã®è¿½å ã§ãããããã¯ãã¼ã¹ã¤ã¡ã¼ã¸ãªã®ã§æ¹åã§ãã¾ããã
ä¸ãã3 çªç®ã¬ã¤ã¤ã¼ã§ã¯ã/var/cache/yum
ã 82B ãã 195MB ã¸å¢å ãã¾ããã
ãã®ã¬ã¤ã¤ã¼å
¨ä½ã®ãµã¤ãºã¯ 206MB ãªã®ã§ãã»ã¨ãã©ã/var/cache/yum
ã¨åããã¾ãã
é»è²ã¯é¸æããã¬ã¤ã¤ã¼ã«ãã£ã¦ãµã¤ãºãå¤ãã£ãé¨åã表ãã¦ãã¾ãã
ãã®ã¬ã¤ã¤ã¼ã§ã¯yum install -y tar which gzip
ãå®è¡ããã¦ãã¾ãã
ãããã®ã³ãã³ãã¯å®è¡ã§ããã°åé¡ãªãã®ã§ 195MB ã®è¨å¤§ãªãã£ãã·ã¥ã¯ä¸è¦ã§ãã
ãã®ããã« dive ãå©ç¨ãããã¨ã§ä¸è¦ãªãã¡ã¤ã«ãçºè¦ãããã¨ãã§ãã¾ããã ãã¨ã¯ãDockerfile ä¸ã§ä¸è¦ãªãã¡ã¤ã«ãåé¤ããã°å®äºã§ãã
RUN yum install -y tar which gzip \ && rm -rf /var/cache/yum/* \ && yum clean all
ãã®ããã«ããã°ããã£ãã·ã¥ã¯åé¤ã§ãã¾ãã
&&
ã§ã¤ãªããªãã¨ä½è¨ãªã¬ã¤ã¤ã¼ã追å ãããã ãã§è»½éåã«ã¯ç¹ããã¾ããã
å
ã
ã®ã¤ã¡ã¼ã¸ãµã¤ãºã¯ 659MB ã§ããããå¤æ´å¾ã¯ 464MB ã«åæ¸ãããã¨ãã§ãã¾ããã
ã¡ããã©ã/var/cache/yum
ã® 195MB åã§ãã
ããã§ã®ä¿®æ£ã¯ãã«ãªã¯ã¨ã¹ãã¨ãã¦åºãã¦ãã¼ã¸ããã¾ããã github.com
Mavenã®å ¬å¼Dockerã¤ã¡ã¼ã¸ã«ã³ã³ããªãã¥ã¼ããã¦OSSããã¥ã¼ãããå¬ãã https://t.co/RxBbrRem5f
— kotaroooo0 (@kotaroooo0) 2020å¹´7æ28æ¥
ãããã«
diveã«ãã£ã¦ã¬ã¤ã¤ã¼ã®ãã£ã¬ã¯ããªãã¨ããã¡ã¤ã«ãã¨ã«ãµã¤ãºã®å¤åã観å¯ãããã¨ãã§ãã¾ããã
ããªãå¼·åãªãã¼ã«ã ãªã¨æãã¾ããã
欲ãè¨ããªããååé ã§ã½ã¼ãã§ã¯ãªããµã¤ãºé ã§ã½ã¼ãã§ããããã«ãªã£ããã^Space
ã§ãªãéãã³ãã³ãã§ãã£ã¬ã¯ããªãç³ãããå¬ããã¨æãã¾ããã
ã¾ããã³ãã³ãã«ãã£ã¦ã©ããªãã¡ã¤ã«ãçæããããåããããããããããã±ã¼ã¸ããã¼ã¸ã£ã®ã³ãã³ãããªã«ããã¦ããããç解ãé²ãã¨ããå¬ããå¯ä½ç¨ãããã¾ããã
ä»å㯠dive ã使ãã®ãååç®çã ã£ãã®ã§dive -> Dockerfileã®é ã§è¦ãã®ã§ãããDockerfile -> diveã®é ã§è¦ãã°yum install
ã®ãã£ãã·ã¥ãåé¤ããã°ããããã ãªã¨å½ãããã¤ãããã¨ãã§ããããããã¾ããã
ã¾ãããå
¬å¼Dockerã¤ã¡ã¼ã¸ã«ãããªã«ã·ã³ãã«ãªä¿®æ£ç®æãæ®ã£ã¦ããã¨ã¯æãã¾ããã§ããã
å¶ç¶ã«ãOSSã¸è²¢ç®ãããã¨ãã§ãã©ããã¼ã§ããã
éå»ã«æ¸ãã Docker ãã«ãé¢ä¿ã®è¨äº
GitHub Actionsを例にCI環境でのマルチステージビルドのキャッシュの活用について🐳 - 🤖
GitHub ActionsでのDockerビルドをキャッシュで高速化する - 🤖
Dockerfileを正しく書けるように指摘してくれる静的解析ツール「hadolint」 - 🤖
Dockerイメージのビルドで使うキャッシュの種類(レイヤーキャッシュ, BuildKit, CI) - 🤖