ã¤ã±ã¦ãã¨ã³ã¸ãã¢ã«ãªããã·ãªã¼ãº ãDockerã¬ãå ¥éç·¨ã
ãã°ããè¨äºãæ¸ãã¦ããªãã£ãã®ã§ä¹ ãã¶ãã®ãã¹ãã§ã
ãã¦ãåã¯1å¹´åãããåãã Docker ã使ãåãã¦ãä»ã§ã¯ä½ãã¢ããªã±ã¼ã·ã§ã³ãéçºããã¨ãã¯ç©æ¥µçã« Docker ã使ã£ã¦ãã¾ã
Dockerfile ã§ç°å¢æ§ç¯ã®æé ããã®ã¾ã¾æ®ãããç°å¢å·®ç°ãæ°ã«ããªãã¦è¯ããªãããåãç¶æ
ã®ããã°ã©ã ãç°å¢ã㨠Docker ã¤ã¡ã¼ã¸ã¨ãã¦æ±ããã®ãæé«ã ã¨æã£ã¦ãã¾ã
ä»åã¯ä¸åº¦ã¯ã¡ããã¨èª¿ã¹ã¦ããããã¨æã£ã¦ãã Docker ãå©ç¨ãã¦ãããã¡ã¤ã«ã·ã¹ãã ã®ä»çµã¿ã«ã¤ãã¦æ¸ãããã¨æãã¾ã
ãã®è¨äºã§ã¯
1. Docker ã®ãã¡ã¤ã«ã·ã¹ãã ã«å¯¾ãããã£ããã®ç解
2. Docker ãå©ç¨ãããã¡ã¤ã«ã·ã¹ãã
3. ã½ã¼ã¹ã³ã¼ããè¦ã¦ã¿ã
4. ã¾ã¨ã
ã«ã¤ãã¦æ¸ãã¾ã
Docker å ¥éã¦ããªã¿ã¤ãã«ã§ãããGet started ã¿ãããªãã¨ã§ã¯ãªã Docker ã®ä½¿ãæ¹ã¨ãã¯ä¸ååºã¦ãã¾ããã®ã§ãã®ç¹ãäºæ¿ãã ããã»ã»ã»
1. Docker ã®ãã¡ã¤ã«ã·ã¹ãã ã«å¯¾ãããã£ããã®ç解
ãã¦ãDocker ã¤ã¡ã¼ã¸ããã¡ã¤ã«ã·ã¹ãã ã«ã¤ãã¦èª¬æãããæã¯ã以ä¸ã®å³ã®ããã«è¤æ°ã®ã¬ã¤ã¤ã¼ãéãã¦ããå³ãããè¦ããã¾ã
åã㦠Docker ã使ã人ã«ã¨ã£ã¦ã¯ããã¨è¦ã§åãããããã®ããããã¾ããããå®éã« Docker ããããã使ã£ã¦ããæè¦ãæã£ã¦æ¹ãã¦ãã®å³ãè¦ã¦èº«ãã¨ãDocker ã®ãã¡ã¤ã«ã·ã¹ãã ã®åä½ã¯ãã®å³ã ãã ã¨ãªããªãã¤ã¡ã¼ã¸ã§ããªãããªã¼ã¨ãµã¨æãã¾ãã
ããã§ãDocker ã®ãã¡ã¤ã«ã·ã¹ãã ã®å ¨ä½ã«ã¤ãã¦ã ããããããªã¤ã¡ã¼ã¸ãæã£ã¦ããã°åé¡ãªãã§ãããã¨ããã®ããã£ãã1æã®å³ã«è©°ãè¾¼ãã§ã¿ã¾ãã
ããããè©°ãè¾¼ã¿ããã¦ã«ãªã¹ã«ãªã£ã¦ãã¾ãã¾ãããããã¤ã³ããåæããã¨ãããªæãã§ã
- Dockerfile ã«æ¸ããã1ã¤ã®ã³ãã³ãã«å¯¾å¿ãã¦1ã¤ã®ã¬ã¤ã¤ã¼ãä½æããã
- ã¤ã¡ã¼ã¸å ã®ãã¡ã¤ã«ã¯èªã¿åãå°ç¨ã¨ãã¦æ±ããå¤æ´ããããã¨ã¯ãªã
- ã³ã³ããã®å®è¡æã«ã¯ã³ã³ããå°ç¨ã®æ¸ãè¾¼ã¿å¯è½ã¬ã¤ã¤ã¼ããã¦ã³ãããã
- ã³ã³ããå
ã®ãã¡ã¤ã«ãåç
§ããå ´å
- è¤æ°ã®ã¬ã¤ã¤ã¼ã«åããã¡ã¤ã«ãåå¨ããå ´åã¯æä¸ä½ã¬ã¤ã¤ã¼ã®ãã®ãå©ç¨
- ã³ã³ããå
ã®ãã¡ã¤ã«ãå¤æ´ãããå ´å
- å ã®ãã¡ã¤ã«ãæ¸ãè¾¼ã¿å¯è½ã¬ã¤ã¤ã¼ã«ã³ãã¼ããå¤æ´
- ã³ã³ããå
ã®ãã¡ã¤ã«ãåé¤ãããå ´å
- æ¸ãè¾¼ã¿å¯è½ã¬ã¤ã¤ã¼ã«ç¹æ®ãã¡ã¤ã«ãä½æããã¦ã¢ã¯ã»ã¹ã§ããªãããå¶å¾¡
ãããæ©è½ã¯å®éã®ã¨ããã©ããã£ã¦å®ç¾ããã¦ãããã ããï¼ã¨ããã®ãæ°ã«ãªã£ã¦ãã¾ãã
ããã㯠Docker ãå©ç¨ãã¦ãããã¡ã¤ã«ã·ã¹ãã ã®ä»çµã¿ã«ãã£ã¦å®ç¾ããã¦ãã¾ã
ã¬ãå ¥éæããã£ã¦ã¯ã¯ã¯ã¯ãã¦ãã¾ããã
2. Docker ãå©ç¨ãããã¡ã¤ã«ã·ã¹ãã
ãã¦ãããã§ã¯ Docker ãå©ç¨ãããã¡ã¤ã«ã·ã¹ãã ã«ã¤ãã¦è©³ç´°ãè¦ã¦ããã¾ããã
åè¿°ã®å³ã§ã¯ãåã¬ã¤ã¤ã¼æ¯ã«é¨åçãªãã£ã¬ã¯ããªæ§é ãä¿æããã¦ãã¦ãDockerã¤ã¡ã¼ã¸å
¨ä½ã¨ãã¦ã¯åã¬ã¤ã¤ã¼ãæã¤ãã£ã¬ã¯ããªæ§é ã®åã¨ãã¦å©ç¨ããã¦ããã¨èª¬æãã¾ãã
ãã®åä½ã¯ UnionFileSystem ã¨ããä»çµã¿ã®ãã¡ã¤ã«ã·ã¹ãã ã«ãã£ã¦å®ç¾ããã¦ãã¾ã
UnionFileSystem ã¯åããã¦ã³ããã¤ã³ãã«è¤æ°ã®ãã£ã¹ã¯ããã¦ã³ãããããããã«å«ã¾ãããã£ã¬ã¯ããªæ§é ã®åã¨ãã¦æ±ãä»çµã¿ãæä¾ãããã¡ã¤ã«ã·ã¹ãã ã§ã
è¨èã ã¨èª¬æãé£ããã®ã§å³ã«æ¸ãã¦ã¿ãã¨ãããªæãã§ã
è¤æ°ã®ãã£ã¹ã¯ã«åããã£ã¬ã¯ããªããã¡ã¤ã«ãã«åå¨ããå ´åã«ã¯å¾ãããã¦ã³ããããã£ã¹ã¯ã®ãã®ãåªå ããã¾ã
UnionFileSystem ã§ã®ãã¡ã¤ã«ã®ä½æãæ´æ°ãåé¤ã«ã¤ãã¦ã¯ã
- æ°è¦ã«ä½æããå ´åã¯æä¸ä½ã®æ¸ãè¾¼ã¿å¯è½ãªãã£ã¹ã¯ã«ä½æ
- èªã¿åãå°ç¨ã®é åã«å¯¾ãã¦æ´æ°ããå ´åã¯ãæ¸ãè¾¼ã¿æã«ã³ãã¼ãä½æãã¦æ´æ°
- èªã¿åãå°ç¨ã®é åã«å¯¾ãã¦åé¤ããå ´åã¯ãwhiteout ãã¡ã¤ã«ã¨ããç¹æ®ãªãã¡ã¤ã«ãä½æãã¦åä½ä¸è¦ããªããã
ã¨ããåä½ããã¾ã
ãã®ä»çµã¿ãç解ã§ãã㨠Docker ã¤ã¡ã¼ã¸ãã³ã³ããå ã®ãã¡ã¤ã«ã·ã¹ãã ã®åä½ã¯ UnionFileSystem ã®åä½ã®éãã ãªã¼ã¨ããã®ããããããã¾ãã
ã¾ããUnionFileSystem ã«ã¯ãããããªç¨®é¡ã®ã®å®è£
ããããDocker ã§ã¯ã©ã®å®è£
ãå©ç¨ãããã StorageDriver ã§é¸æã§ããããã«ãªã£ã¦ãã¾ã
docs.docker.com
Dockerãç»å ´ããå½åãããã°ãã㯠AUFS ã使ããã¦ããããã§ãããç¾å¨ã®å
¬å¼ããã¥ã¡ã³ãã§ã¯ AUFS ãããããã©ã¼ãã³ã¹ãé«ãã¨ããçç±ã§ OverlayFS ã®å©ç¨ãæ¨å¥¨ããã¦ããããã§ãã
docs.docker.com
UnionFileSystem ã¯å½ç¶ãªãã Docker ãã³ã³ããã ãã®ããã®ãã®ã§ã¯ãªãã身è¿ãªä¾ã 㨠LiveCD ãªã©ã§å¤é¨ã¹ãã¬ã¼ã¸ãã OS ãèµ·åããéã«ãå©ç¨ããã¦ããããã§ã
ãã®ä» UnionFileSystem ã«ã¤ãã¦ã®è©³ç´°ã¯ãã¡ãã®è¨äºãé常ã«åãããããã£ãã®ã§ãã²ä¸åº¦èªãã§ã¿ã¦ãã ãã
UnionMountとUnion-type Filesystem(1) - O'Reilly Japan Community Blog
3. ã½ã¼ã¹ã³ã¼ããè¦ã¦ã¿ã
ãã¦ãUnionFileSystem ã®ä»çµã¿ã«ãã£ã¦ Docker ã®ãã¡ã¤ã«ã·ã¹ãã ãæ§æããã¦ãããã¨ãåããã¾ããããæ¬å½ã«ãããªã®ãã³ã¼ããè¦ã¦ã¿ãããªã£ã¦ãã¾ããã
Docker ã®ã½ã¼ã¹ã³ã¼ãã¯ãã¡ãã®2ã¤ã®ãªãã¸ããªã«ããã¾ãã
https://github.com/docker/engine
https://github.com/moby/moby
Docker ã¯2017å¹´ã« Docker ã®ã³ã¢é¨åã OSS ã«ãã mobyããã¸ã§ã¯ãã¨ããã®ãçºè¶³ãã¦ãããDocker ã®å®è£
㯠moby ã®ã³ã¼ãããã¼ã¹ã«ããã¦ããããã§ã
Github ä¸ã§ã docker/engine 㯠moby/moby ã fork ãã¦ä½ããã¦ããã®ãåããã¾ãã
å®éã«ä¸èº«ãè¦ã¦ããã¨ç¢ºãã«å®è£
ã®å¤§é¨å㯠moby ã®ã³ã¼ããå©ç¨ãã¦ããããã§ãã
Docker ã§ã¯1ã¤ã®ã¬ã¤ã¤ã¼æ¯ã«å¯¾å¿ãããã£ã¬ã¯ããªãä½æããããã®ãã£ã¬ã¯ããªã UnionFileSystem ã®ä»çµã¿ã«ãã£ã¦ãã¦ã³ããã¦ããããã§ã
ãã®è¾ºãã®ã³ã¼ãã«æ°ããã¬ã¤ã¤ã¼(=æ°ãããã£ã¬ã¯ããª)ãä½ãå¦çãæ¸ããã¦ãã¾ã
https://github.com/docker/engine/blob/master/daemon/graphdriver/overlay/overlay.go#L280
https://github.com/docker/engine/blob/master/layer/layer_store.go#L479
ã¾ããã®ãã¹ãã³ã¼ãã§ã¯2ã¤ã®ã¬ã¤ã¤ã¼ããã¦ã³ãããæã®æåããã¹ãããã¦ãã¾ã
https://github.com/docker/engine/blob/master/layer/mount_test.go#L14
åè¿°ã® UnionFileSystem ã®æåã¨åæ§ã®åä½ã確èªãããã¹ããæ¸ããã¦ãã¾ã
ãã®ä»ã«ã Docker ã¤ã¡ã¼ã¸ããã«ãããéã® `ADD`ã`RUN` ã«å¯¾å¿ããå¦çã®ã³ã¼ãã¯ãããã追ã£ã¦ãããã¨ãã§ãã¾ã
https://github.com/docker/engine/blob/master/builder/dockerfile/dispatchers.go#L90
https://github.com/docker/engine/blob/master/builder/dockerfile/dispatchers.go#L341
é¢é£ããã³ã¼ãã大éã«ããããã¦ãã¾ãã¾ã¨ããããªãã£ãã®ã§ãã³ã¼ãã®ãç´¹ä»ã¯ãã®ç¨åº¦ã§ã»ã»ã»
ãããããªé¨åãæ½è±¡åããã¦ããã®ã§ãããã«æ¸ãã¦ãï¼ã¨ããã®ã¯ç¤ºãã«ããã§ãã
大æ ã®ã¤ã¡ã¼ã¸ã¨ãã¦ã¯ããã¾ã§ã«æ²è¼ããå³ã®éãã§ãããã½ã¼ã¹ã³ã¼ããè¦ããã¨ã§å®éã«ãã®éãã«å®ç¾ããã¦ããã¨ãããã¨ãããåããã¾ãã
4. ã¾ã¨ã
ãã¦ãä»å㯠Docker ã¬ãå
¥éã¨ãããã¨ã§ Docker ãå©ç¨ãã¦ãããã¡ã¤ã«ã·ã¹ãã ã«ã¤ãã¦è©³ç´°ãè¦ã¦ããã¾ãã
ä»å調ã¹ãå
容ãé ã«å
¥ã£ã¦ããã¨ãDocker ã¬ãå
¥éã®ç¬¬ä¸æ©ãè¸ã¿åºãããããªæ°ããã¦ãã¾ãã
ããã»ã¹åé¢ã®ä»çµã¿ãåä¸ãã¹ãå ã§ã®ã»ãã¥ãªãã£ã¨ããã®ã奥ãæ·±ããã ã£ãã®ã§ãã¾ããã³ã·ã§ã³ãä¸ãã£ã¦ããã調ã¹ã¦ç¶ããæ¸ãããã¨æãã¾ã
å®ç¨ä¸ã§ã¯ Docker ãåä½ã§ä½¿ãã¨ããå ´é¢ã¯ãã¾ãç¡ãã大æµã¯ Kubernetes ã¨ãã®ãªã¼ã±ã¹ãã¬ã¼ã·ã§ã³ãã¼ã«ãå©ç¨ãããã¨ã«ãªãã¨æãã¾ã
å人çã«ã¯ããããã使ããã¨ã§ã¢ããªã±ã¼ã·ã§ã³ã¹ã¿ãã¯ã丸ãã¨å®ç¾©ã§ãã¦ãé常ã«ç°¡åã«ç°å¢ãåç¾ãã¦åãããã¨ããã¨ããã«ã¨ã¦ãé
åãæãã¦ã¾ã
ãµã¼ãã¼ãµã¤ãã¨ã³ã¸ãã¢ãã¤ã³ãã©ãå«ãã¦ããã°ã©ãã³ã°ãããã¨ãã¨ã¦ãç°¡åã«ãªããå®éã®æ¥åã§ãä¸æ°ã«ã§ãããã¨ã®å¹
ãåºãã£ãæãããã¦ãã¾ã
ä»åè²ã ã¨èª¿ã¹ã¦ã¿ã¦ãä»ã¾ã§ã®èªè㯠"Docker ã便å©ã ï¼" ã¨ããç¨åº¦ã§èªèãåºå®ããã¦ãã¦ãã¾ã£ããã§ããã©ãæè¡çã«ã¯æããåå¨ãã¦ãããã®ãéçºè ã®ãããã¤ã»ããªããªã¼ã®è¦ç¹ã§ããç°¡åã«ä½¿ãããããããã®ã Docker ãªãã ãªã¼ã¨ãããã¨ãããåããã¾ãã
ã³ã³ããã®åéãä¸æ°ã«çãä¸ãã Docker ã¯é常ã«ç´ æ´ãããã½ããã¦ã§ã¢ã ã¨æãã¾ããããã®ä»ã®ã³ã³ããæè¡ã«ãç¹è²ãããããããé²åãã¦ãããããªã®ã§ãDockerãKubernetesã«éããä»å¾ãæ§ã ãªè£½åãç©æ¥µçã«ä½¿ã£ã¦ãããã¨ãããã¾ã
çãããå¿«é©ãªã³ã³ããã©ã¤ããï¼