ãã®èšäºã®èè
ã¯ãæ¬æ¥ç¿»èš³ãå
¬éããŠããŸãããDocker ComposeãåŠã³ãããDockerã䜿çšããŠæåã®ã¯ã©ã€ã¢ã³ããµãŒããŒã¢ããªã±ãŒã·ã§ã³ãäœæããéçºè
ã察象ãšããŠããŸãã èªè
ã¯Dockerã®åºæ¬ã«ç²ŸéããŠããã¯ãã§ãã ããã§ãªãå Žåã¯ã
ãã®äžé£ã®è³æãDockerã®åºæ¬ãKubernetesã®åºæ¬ãšäžç·ã«èª¬æããŠãã
ãã®åºçç©ãããã³åå¿è
åãã®
ãã®èšäºãã芧ãã ããã
Docker Composeãšã¯äœã§ããïŒ
Docker Composeã¯ãDockerã«å«ãŸããŠããããŒã«ã§ãã ãããžã§ã¯ãã®å±éã«é¢é£ããåé¡ã解決ããããã«èšèšãããŠããŸãã
Dockerã®åºæ¬ãåŠç¿ãããšãããšãã°å€éšããŒã¿ãœãŒã¹ãç¹å®ã®ãµãŒãã¹ããç¬ç«ããŠãèªåŸçã«åäœããåçŽãªã¢ããªã±ãŒã·ã§ã³ã®äœæã«ééãããããããŸããã å®éã«ã¯ããã®ãããªã¢ããªã±ãŒã·ã§ã³ã¯ãŸãã§ãã éåžžãå®éã®ãããžã§ã¯ãã«ã¯ãã³ã©ãã¬ãŒã·ã§ã³ã¢ããªã±ãŒã·ã§ã³ã®ã»ããå
šäœãå«ãŸããŸãã
ãããžã§ã¯ãããããã€ãããšãã«Docker Composeã䜿çšããå¿
èŠããããã©ããã¯ã©ã®ããã«ããããŸããïŒ å®éãéåžžã«ç°¡åã§ãã ãã®ãããžã§ã¯ãã®æ©èœãä¿èšŒããããã«è€æ°ã®ãµãŒãã¹ã䜿çšãããŠããå ŽåãDocker Composeã圹ç«ã¡ãŸãã ããšãã°ããŠãŒã¶ãŒãèªèšŒããããã«ããŒã¿ããŒã¹ã«æ¥ç¶ããå¿
èŠãããWebãµã€ããäœæããç¶æ³ã§ã åæ§ã®ãããžã§ã¯ãã¯2ã€ã®ãµãŒãã¹ã§æ§æã§ããŸãã1ã€ã¯ãµã€ãã®éçšãä¿èšŒãããã1ã€ã¯ããŒã¿ããŒã¹ã®ä¿å®ãæ
åœããŸãã
Docker Composeãã¯ãããžãŒã¯ãç°¡åã«èª¬æãããšã1ã€ã®ã³ãã³ãã§å€ãã®ãµãŒãã¹ãèµ·åã§ããŸãã
DockerãšDocker Composeã®éã
Dockerã¯ãã¢ããªã±ãŒã·ã§ã³ãæ§æããåã
ã®ã³ã³ããïŒãµãŒãã¹ïŒã管çããããã«äœ¿çšãããŸãã
Docker Composeã¯ãã¢ããªã±ãŒã·ã§ã³ãæ§æããè€æ°ã®ã³ã³ãããŒãåæã«ç®¡çããããã«äœ¿çšãããŸãã ãã®ããŒã«ã¯Dockerãšåãæ©èœãæäŸããŸãããããè€éãªã¢ããªã±ãŒã·ã§ã³ã§äœæ¥ã§ããŸãã
DockerïŒåäžã³ã³ãããŒïŒããã³Docker ComposeïŒè€æ°ã³ã³ãããŒïŒå
žåçãªDocker ComposeãŠãŒã¹ã±ãŒã¹
Docker Composeã¯ãéåžžã«åŒ·åãªããŒã«ã§ãããè€éãªã¢ãŒããã¯ãã£ã®ã¢ããªã±ãŒã·ã§ã³ãè¿
éã«ãããã€ã§ããŸãã 次ã«ãDocker Composeã®å®éã®äœ¿çšäŸãèŠãŠã¿ãŸãããããã®åæã«ãããDocker Composeã䜿çšããå©ç¹ãè©äŸ¡ã§ããŸãã
ããªããWebãããžã§ã¯ãã®éçºè
ã§ãããšæ³åããŠãã ããã ãã®ãããžã§ã¯ãã«ã¯2ã€ã®Webãµã€ããå«ãŸããŸãã 1ã€ç®ã¯ãããžãã¹ã®äººã
ãæ°åã¯ãªãã¯ããã ãã§ãªã³ã©ã€ã³ã·ã§ããã³ã°ãäœæã§ããããã«ããŸãã 2ã€ç®ã¯ãã«ã¹ã¿ããŒãµããŒããç®çãšããŠããŸãã ããã2ã€ã®ãµã€ãã¯åãããŒã¿ããŒã¹ãšå¯Ÿè©±ããŸãã
ããªãã®ãããžã§ã¯ãã¯ãŸããŸã人æ°ãåºãŠããŠããããããåäœãããµãŒããŒã®èœåã¯ãã¯ãååã§ã¯ãªãããšãå€æããŠããŸãã ãã®çµæããããžã§ã¯ãå
šäœãå¥ã®ãã·ã³ã«è»¢éããããšã«ããŸããã
æ®å¿µãªãããDocker Composeãªã©ã¯äœ¿çšããŸããã§ããã ãããã£ãŠããã®äœæ¥ã®éçšã§äœãå¿ããªãããã«ããµãŒãã¹ãäžåºŠã«1ã€ãã€è»¢éããã³åæ§æããå¿
èŠããããŸãã
Docker Composeã䜿çšããå Žåããããžã§ã¯ããæ°ãããµãŒããŒã«è»¢éããããšã¯ãããã€ãã®ã³ãã³ããå®è¡ããããšã§è§£æ±ºã§ããåé¡ã§ãã ãããžã§ã¯ãã®æ°ããå Žæãžã®è»¢éãå®äºããã«ã¯ãããã€ãã®èšå®ãå®è¡ããããŒã¿ããŒã¹ã®ããã¯ã¢ããã³ããŒãæ°ãããµãŒããŒã«ã¢ããããŒãããã ãã§ãã
Docker Composeã䜿çšããã¯ã©ã€ã¢ã³ããµãŒããŒã¢ããªã±ãŒã·ã§ã³ã®éçº
ããã§Docker Composeã®äœ¿çšç®çãããã£ãã®ã§ããã®ããŒã«ã䜿çšããŠæåã®ã¯ã©ã€ã¢ã³ããµãŒããŒã¢ããªã±ãŒã·ã§ã³ãäœæããŸãã ã€ãŸããããã¹ãã®æçãå«ããã¡ã€ã«ãäœæã§ããPythonã®å°ããªWebãµã€ãïŒãµãŒããŒïŒã®éçºã«ã€ããŠè©±ããŠããã ãã®ãã¡ã€ã«ã¯ãåããPythonã§æžãããããã°ã©ã ïŒã¯ã©ã€ã¢ã³ãïŒã«ãã£ãŠãµãŒããŒããèŠæ±ãããŸãã ãµãŒããŒãããã¡ã€ã«ãåä¿¡ããåŸãããã°ã©ã ã¯ç»é¢ã«ä¿åãããŠããããã¹ãã衚瀺ããŸãã
Dockerã®åºæ¬ãææããDockerãã©ãããã©ãŒã ãæ¢ã«ã€ã³ã¹ããŒã«ãããŠããããšãæåŸ
ããŠããããšã«æ³šæããŠãã ããã
ãããžã§ã¯ãã«åãæãããŸãããã
â1ã ãããžã§ã¯ãäœæ
æåã®ã¯ã©ã€ã¢ã³ããµãŒããŒã¢ããªã±ãŒã·ã§ã³ãæ§ç¯ããã«ã¯ããããžã§ã¯ããã©ã«ããŒã®äœæããå§ããããšããå§ãããŸãã 次ã®ãã¡ã€ã«ãšãã©ã«ããŒãå«ãŸããŠããå¿
èŠããããŸãã
docker-compose.yml
ã ããã¯Docker Composeãã¡ã€ã«ã§ããããµãŒãã¹ãéå§ããã³æ§æããããã«å¿
èŠãªæ瀺ãå«ãŸããŸããserver
ãã©ã«ããŒã ãµãŒããŒã®åäœãä¿èšŒããããã«å¿
èŠãªãã¡ã€ã«ãå«ãŸããŸãã- ãã©ã«ããŒ
client
ã ã¯ã©ã€ã¢ã³ãã¢ããªã±ãŒã·ã§ã³ã®ãã¡ã€ã«ã¯æ¬¡ã®ãšããã§ãã
ãã®çµæããããžã§ã¯ãã®ã¡ã€ã³ãã©ã«ããŒã®å
容ã¯æ¬¡ã®ããã«ãªããŸãã
. âââ client/ âââ docker-compose.yml âââ server/ 2 directories, 1 file
â2ã ãµãŒããŒäœæ
ããã§ã¯ããµãŒããŒãäœæããéçšã§ãDockerã«é¢ããããã€ãã®åºæ¬çãªäºé
ã«è§ŠããŸãã
2aã ãã¡ã€ã«äœæ
server
ãã©ã«ããŒã«ç§»åãããã®äžã«æ¬¡ã®ãã¡ã€ã«ãäœæããŸãã
server.py
ãã¡ã€ã«ã ãµãŒããŒã³ãŒããå«ãŸããŸããindex.html
ãã¡ã€ã«ã ãã®ãã¡ã€ã«ã«ã¯ãã¯ã©ã€ã¢ã³ãã¢ããªã±ãŒã·ã§ã³ã衚瀺ããããã¹ããå«ãŸããŸããDockerfile
ãã¡ã€ã«ã ããã¯ããµãŒããŒç°å¢ã®äœæã«å¿
èŠãªæ瀺ãå«ãDockerãã¡ã€ã«ã§ãã
server/
ãã©ã«ããŒã®å
容ã¯æ¬¡ã®ããã«ãªããŸãã
. âââ Dockerfile âââ index.html âââ server.py 0 directories, 3 files
2bã Pythonãã¡ã€ã«ã®ç·šéã
server.py
ãã¡ã€ã«ã«æ¬¡ã®ã³ãŒããè¿œå ããŸãã
ãã®ã³ãŒãã䜿çšãããšãç°¡åãªWebãµãŒããŒãäœæã§ããŸãã ã¯ã©ã€ã¢ã³ãã«
index.html
ãã¡ã€ã«ãæäŸãããã®å
容ã¯åŸã§WebããŒãžã«è¡šç€ºãããŸãã
2cã HTMLãã¡ã€ã«ã®ç·šé
次ã®ããã¹ãã
index.html
ãã¡ã€ã«ã«è¿œå ããŸãã
Docker-Compose is magic!
ãã®ããã¹ãã¯ã¯ã©ã€ã¢ã³ãã«éä¿¡ãããŸãã
2dã Dockerfileã®ç·šé
ããã§ãPythonãµãŒããŒã®ã©ã³ã¿ã€ã ãæŽçããåçŽãª
Dockerfile
ãäœæããŸãã äœæãããã€ã¡ãŒãžã®åºç€ãšããŠãPythonã§æžãããããã°ã©ã ã®å®è¡ãç®çãšãã
å
¬åŒã€ã¡ãŒãžã䜿çšããŸãã Dockerfileã®å
容ã¯æ¬¡ã®ãšããã§ãã
ããã§ã¯ãã¯ã©ã€ã¢ã³ãã§äœæ¥ããŸãããã
â3ã 顧客ã®åµé
ãããžã§ã¯ãã®ã¯ã©ã€ã¢ã³ãéšåãäœæããDockerã®åºæ¬ã®ããã€ããåæã«æãåºããŸãã
3aã ãã¡ã€ã«äœæ
client
ãããžã§ã¯ãã®ãã©ã«ããŒã«ç§»åãããã®äžã«æ¬¡ã®ãã¡ã€ã«ãäœæããŸãã
client.py
ãã¡ã€ã«ã ãããã¯ã©ã€ã¢ã³ãã³ãŒãã«ãªããŸããDockerfile
ãã¡ã€ã«ã ãã®ãã¡ã€ã«ã¯ããµãŒããŒãã©ã«ããŒå
ã®åæ§ã®ãã¡ã€ã«ãšåã圹å²ãæãããŸãã ã€ãŸããã¯ã©ã€ã¢ã³ãã³ãŒããå®è¡ããããã®ç°å¢ã®äœæã説æããæ瀺ãå«ãŸããŠããŸãã
ãã®çµæããã®äœæ¥æ®µéã§ã®
client/
ãã©ã«ããŒã¯æ¬¡ã®ããã«ãªããŸãã
. âââ client.py âââ Dockerfile 0 directories, 2 files
3bã Pythonãã¡ã€ã«ã®ç·šé
client.py
ãã¡ã€ã«ã«æ¬¡ã®ã³ãŒããè¿œå ããŸãã
ãã®ã³ãŒãã®ãããã§ãã¯ã©ã€ã¢ã³ãã¢ããªã±ãŒã·ã§ã³ã¯ãµãŒããŒããããŒã¿ãããŠã³ããŒãããŠç»é¢ã«è¡šç€ºã§ããŸãã
3cã Dockerfileã®ç·šé
ãµãŒããŒã®å Žåãšåæ§ã«ãã¯ã©ã€ã¢ã³ãçšã®ã·ã³ãã«ãª
Dockerfile
ãäœæããã¯ã©ã€ã¢ã³ãPythonã¢ããªã±ãŒã·ã§ã³ãåäœããç°å¢ãäœæããŸãã ã¯ã©ã€ã¢ã³ã
Dockerfile
ã³ãŒãã¯æ¬¡ã®
Dockerfile
ã§ãã
â4ã Dockeräœæ
ãæ°ã¥ããããããŸãããããµãŒããŒãšã¯ã©ã€ã¢ã³ããšãã2ã€ã®ç°ãªããããžã§ã¯ããäœæããŸããã ããããã«ç¬èªã®
Dockerfile
ãŸãã ãããŸã§ãçºçãããã¹ãŠã®ããšã¯Dockerã䜿çšããåºæ¬ãè¶
ããŠããŸããã çŸåšãDocker Composeã®äœ¿çšãéå§ããŠããŸãã ãããè¡ãã«ã¯ããããžã§ã¯ãã®ã«ãŒããã©ã«ããŒã«ãã
docker-compose.yml
ãã¡ã€ã«ãåç
§ããŸãã
ããã§ã¯ã
docker-compose.yml
䜿çšã§ãããã¹ãŠã®ã³ãã³ããå®å
šã«æ€èšããããšããŠããããã§ã¯ãªãããšã«æ³šæããŠãã ããã ç§ãã¡ã®äž»ãªç®æšã¯ãDocker Composeã®åºæ¬çãªç¥èãæäŸããå®çšçãªäŸãæäŸããããšã§ãã
docker-compose.yml
ã«é
眮ããã³ãŒãã¯æ¬¡ã®ãšãã
docker-compose.yml
ã
â5ã ãããžã§ã¯ãã®çµã¿ç«ãŠ
å¿
èŠãªãã¹ãŠã®æ瀺ã
docker-compose.yml
å«ãŸãããããããžã§ã¯ããã¢ã»ã³ãã«ããå¿
èŠããããŸãã äœæ¥ã®ãã®ã¹ãããã¯ã
docker build
䜿çšã«äŒŒãŠããŸããã察å¿ããã³ãã³ãã¯ããã€ãã®ãµãŒãã¹ã«é¢é£ããŠããŸãã
$ docker-compose build
â6ã ãããžã§ã¯ãã®éå§
ãããžã§ã¯ããå®äºããã®ã§ãä»åºŠã¯ãããžã§ã¯ããéå§ããŸãã äœæ¥ã®ãã®ã¹ãããã¯ãåã
ã®ã³ã³ãããŒãæäœãããšãã«ã
docker run
ã³ãã³ããå®è¡ãããã¹ãããã«å¯Ÿå¿ããŸãã
$ docker-compose up
ãã®ã³ãã³ããå®è¡ãããšãã¿ãŒããã«ã¯ã¯ã©ã€ã¢ã³ãããµãŒããŒããããŠã³ããŒãããããã¹ãã衚瀺ããã¯ãã§ãïŒ
Docker-Compose is magic!
ã
æ¢ã«è¿°ã¹ãããã«ããµãŒããŒã¯ã³ã³ãã¥ãŒã¿ãŒããŒã
1234
ã䜿çšããŠã¯ã©ã€ã¢ã³ãèŠæ±ãåŠçããŸãã ãããã£ãŠã
httpïŒ// localhostïŒ1234 /ã§ãã©ãŠã¶ãŒã«ã¢ã¯ã»ã¹ãããšã
Docker-Compose is magic!
ãšããããã¹ãã®ããŒãžã衚瀺ãããŸã
Docker-Compose is magic!
ã
䟿å©ãªã³ãã³ã
Docker Composeã§äœæ¥ãããšãã«åœ¹ç«ã€ãšæãããã³ãã³ãã®ããã€ããèŠãŠã¿ãŸãããã
ãã®ã³ãã³ãã䜿çšãããšã
docker-compose up
äœæãããã³ã³ããããã³ãã®ä»ã®ãªãœãŒã¹ãåæ¢ããã³åé€ã§ããŸãã
$ docker-compose down
次ã®ã³ãã³ãã¯ããµãŒãã¹ãã°ã衚瀺ããŸãã
$ docker-compose logs -f [service name]
ããšãã°ããããžã§ã¯ãã§ã¯ã次ã®åœ¢åŒã§äœ¿çšã§ããŸãïŒ
$ docker-compose logs -f [service name]
ã
ãã®ã³ãã³ãã䜿çšããŠãã³ã³ãããŒããªã¹ãã§ããŸãã
$ docker-compose ps
ãã®ã³ãã³ãã䜿çšãããšãå®è¡äžã®ã³ã³ããã§ã³ãã³ããå®è¡ã§ããŸãã
$ docker-compose exec [service name] [command]
ããšãã°ã
docker-compose exec server ls
ãŸãã
ãã®ã³ãã³ãã䜿çšãããšãç»åã®ãªã¹ãã衚瀺ã§ããŸãã
$ docker-compose images
ãŸãšã
Docker Composeãã¯ãããžã䜿çšããåºæ¬ã«ã€ããŠæ€èšããŸãããDockerComposeã®ç¥èã«ããããã®ãã¯ãããžã䜿çšããå¿
èŠã«å¿ããŠè©³çŽ°ãªèª¿æ»ãéå§ã§ããŸãã
ããã«ãããã§ã¬ãã¥ãŒãããããžã§ã¯ãã³ãŒããå«ããªããžããªã瀺ããŸãã
芪æãªãèªè
ïŒ ãããžã§ã¯ãã§Docker Composeã䜿çšããŠããŸããïŒ