ãæ¢ãã®ã¯ã€ãã¯ã¹ã¿ãŒãã¬ã€ãã
æšå¹ŽãœãããŠã§ã¢ã®ãã¬ã³ããè¿œã£ãã®ã§ããã°ãDockerãšããèšèãèãã®ã«ããããããŠããã«éããããŸããã ã³ã³ãããéé¢ãããä»®æ³ãã·ã³ãã¹ãŒããŒãã€ã¶ãŒãDevOpsã«é¢é£ãããã®ä»ã®Voodooããžãã¯ã«ã€ããŠè©±ããŠããéçºè
ã®å§åçãªæ°ã«å§åãããå¯èœæ§ãé«ãã§ãããã ä»æ¥ã¯ãããç解ããŸãã æåŸã«ããµãŒãã¹ãšããŠã®ã³ã³ãããšã¯äœãããªãã³ã³ãããå¿
èŠãªã®ããç解ããæãæ¥ãŸããã
TL; DR
- ããªããããå¿
èŠãªã®ã§ããïŒã
- ãã¹ãŠã®éèŠãªçšèªã®æŠèŠã
- ãªãCaaSãšDockerãå¿
èŠãªã®ã§ããã
- ã¯ã€ãã¯ã¹ã¿ãŒãã
- Dockerãã€ã³ã¹ããŒã«ããŸãã
- ã³ã³ãããäœæããŸãã
- å®éã®ã·ããªãªã
- éçWebãµã€ãããã¹ãããnginxã³ã³ãããŒãäœæããŸãã
- ãã«ãããŒã«ã䜿çšããŠDockerã³ãã³ããèªååããæ¹æ³ãåŠã³ãŸãã
ããªããããå¿
èŠãªã®ã§ããïŒã
å°ãåãŸã§ãç§ã¯èªåèªèº«ã«åã質åãããŸããã é·ãéé åºãªéçºè
ã§ãã£ãç§ã¯ãã€ãã«åº§ã£ãŠãã³ã³ããã䜿çšããããšã®ãã°ããããåãå
¥ããŸããã ããã«ãããããé©çšããããšããçç±ã«ã€ããŠã®ç§ã®æèŠããããŸãã
DockerïŒ
Docker-ã³ã³ããåãããã¢ããªã±ãŒã·ã§ã³ãäœæããããã®ãœãããŠã§ã¢ã ã³ã³ããã¯å°ããããœãããŠã§ã¢ãå®è¡ããããã®ç°å¢æ
å ±ãä¿åããªãã§ãã ããã
ã³ã³ããã€ã¡ãŒãžã¯ãã³ãŒããã©ã³ã¿ã€ã ãã·ã¹ãã ããŒã«ãã·ã¹ãã ã©ã€ãã©ãªãèšå®ãªã©ãå®è¡ã«å¿
èŠãªãã¹ãŠãå«ããœãããŠã§ã¢ã®è»œéã§ã¹ã¿ã³ãã¢ãã³ã®å®è¡å¯èœããã±ãŒãžã§ãã
-Dockerã®å
¬åŒWebãµã€ãã
èŠããã«ãã³ã³ããã¯ãå
¥ããããã¢ããªã±ãŒã·ã§ã³ãå®è¡ããããã®åºæ¬çãªæ©èœãåããå°ããªä»®æ³ãã·ã³ã§ãã
ä»®æ³ãã·ã³ïŒ
ãä»®æ³ãã·ã³ãïŒVMïŒãšããååã¯ãããèªäœãè¡šããŠããŸããããã¯ããã倧ããªãã·ã³å
ã®ãã·ã³ã®ããŒããŠã§ã¢ãæš¡å£ããå®éã®ãã·ã³ã®ä»®æ³ããŒãžã§ã³ã§ãã ãã®ããã1ã€ã®å€§ããªãµãŒããŒäžã§å€ãã®ä»®æ³ãã·ã³ãå®è¡ã§ããŸãã æ ç»ãBeginningããèŠãããšããããŸããïŒ ä»®æ³ãã·ã³ã¯ãéå§ãã®ãããªãã®ã§ãã VMãæ©èœããããœãããŠã§ã¢ã¯ããã€ããŒãã€ã¶ãŒãšåŒã°ããŸãã
ãã€ããŒãã€ã¶ãŒïŒ
æ°ããçšèªããããé è³ããããŸããïŒ æ£åœãªçç±ã®ããã«ãå°ãæéãããããŸãã ä»®æ³ãã·ã³ã¯ããã€ããŒãã€ã¶ãŒãåå ã§ã®ã¿æ©èœããŸãã ããã¯ãç©çãã·ã³ãè€æ°ã®ç°ãªãä»®æ³ãã·ã³ããã¹ãã§ããããã«ããç¹å¥ãªãœãããŠã§ã¢ã§ãã å€éšããèŠããšãVMã¯ç¬èªã®ããã°ã©ã ãå®è¡ãããã¹ãããŒããŠã§ã¢ã䜿çšããŠããããã§ãã ãã ãããã®ãã€ããŒãã€ã¶ãŒã¯ãªãœãŒã¹ãä»®æ³ãã·ã³ã«å²ãåœãŠãŸãã
泚ïŒãœãããŠã§ã¢ïŒVirtualBoxãªã©ïŒãã€ã³ã¹ããŒã«ããããšããŠå€±æããå Žåã¯ãã³ã³ãã¥ãŒã¿ãŒã®BIOSã§ä»®æ³åã·ã¹ãã ãã¢ã¯ãã£ãã«ãªã£ãŠããªãããšãåå ã§ããå¯èœæ§ããããŸãã ãããããããã¯ç§ãäžåºŠèŠããŠãã以äžã«ç§ã«èµ·ãããŸããã ç¥çµè³ªãªç¬ã**
ããªããç§ã®ãããªãªã¿ã¯ãªããHypervisorãšã¯äœãã«é¢ããçŽ æŽãããæçš¿ããããŸãã
ä»®æ³å101ïŒãã€ããŒãã€ã¶ãŒãšã¯äœã§ããïŒ
質åã«çãã...
CaaSãšã¯äœã§ããïŒ é·ãéãä»®æ³ãã·ã³ã䜿çšããŠããŸãã ã³ã³ãããçªç¶è¯ããªã£ãã®ã¯ãªãã§ããïŒ ä»®æ³ãã·ã³ãæªããšèšã人ã¯èª°ãããŸãããæ±ããé£ããã ãã§ãã
ååãšããŠãDevOpsã¯è€éã§ãããä»»åœããã人ã¯åžžã«åœŒã«é¢é£ããä»äºãããå¿
èŠããããŸãã ä»®æ³ãã·ã³ã¯å€ãã®ã¹ããŒã¹ãšRAMãå æããäžå®ã®æ§æãå¿
èŠã§ãã ããããé©åã«ç®¡çããã«ã¯çµéšãå¿
èŠã§ãããšããäºå®ã¯èšããŸã§ããããŸããã
ããã«ã¯ãŒã¯ãè¡ããªãããã«ãèªååãã
Dockerã§ã¯ãéåžžã®æ§æãšç°å¢èšå®ãç¡èŠããŠã代ããã«ã³ãŒãã£ã³ã°ã«éäžã§ããŸãã Docker Hubã䜿çšãããšãäºåã«äœæãããç»åãååŸããŠãçæéã§æ©èœãããããšãã§ããŸãã
ããããæ倧ã®å©ç¹ã¯ãåçš®ã®ç°å¢ãäœæã§ããããšã§ãã ããŸããŸãªäŸåé¢ä¿ã®ãªã¹ããèšå®ããŠã¢ããªã±ãŒã·ã§ã³ãå®è¡ãã代ããã«ãDockerã®ã¿ãã€ã³ã¹ããŒã«ããå¿
èŠããããŸãã Dockerã¯ã¯ãã¹ãã©ãããã©ãŒã ãªã®ã§ãåããŒã éçºè
ã¯åãç°å¢ã§äœæ¥ããŸãã éçºãæ¬çªãããã³æ¬çªãµãŒããŒã«ã€ããŠãåæ§ã§ãã ããã¯ãããïŒ ãããç§ã®ãã·ã³ã§åãããšããããšã¯ãããŸããã
ã¯ã€ãã¯ã¹ã¿ãŒã
ã€ã³ã¹ããŒã«ããå§ããŸãããã é©ãã¹ãããšã«ãéçºãã·ã³ã«ã€ã³ã¹ããŒã«ãããŠãããœãããŠã§ã¢ã®äžéšã®ã¿ãå¿
èŠã§ããããã¹ãŠãæ£åžžã«æ©èœããŸãã Dockerãããã°ååã§ãã
Dockerãã€ã³ã¹ããŒã«ãã
幞ããªããšã«ãã€ã³ã¹ããŒã«ããã»ã¹ã¯éåžžã«ç°¡åã§ãã ãããã Ubuntuã§ã®ã€ã³ã¹ããŒã«æ¹æ³ã§ãã
$ sudo apt-get update $ sudo apt-get install -y docker.io
å¿
èŠãªã®ã¯ããã ãã§ãã Dockerãæ©èœããŠããããšã確èªããã«ã¯ãå¥ã®ã³ãã³ããå®è¡ã§ããŸãã
$ sudo systemctl status docker
Dockerã¯çµæãè¿ãã¯ãã§ãã
â docker.service â Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2018-01-14 12:42:17 CET; 4h 46min ago Docs: https://docs.docker.com Main PID: 2156 (dockerd) Tasks: 26 Memory: 63.0M CPU: 1min 57.541s CGroup: /system.slice/docker.service ââ2156 /usr/bin/dockerd -H fd:// ââ2204 docker-containerd --config /var/run/docker/containerd/containerd.toml
ã·ã¹ãã ãµãŒãã¹ãåæ¢ããŠããå Žåã¯ã2ã€ã®ã³ãã³ãã®çµã¿åãããå®è¡ããŠDockerãå±éããèµ·åæã«èµ·åããããšã確èªããŸãã
$ sudo systemctl start docker && sudo systemctl enable docker
Dockerã®åºæ¬ã€ã³ã¹ããŒã«ã§ã¯ã docker
ãsudo
ãšããŠå®è¡ããå¿
èŠããããŸãã ãã ãããŠãŒã¶ãŒãdocker
ã°ã«ãŒãã«è¿œå ãããšã sudo
ãªãã§ã³ãã³ããå®è¡ã§ããŸãã
$ sudo usermod -aG docker ${USER} $ su - ${USER}
ã³ãã³ããå®è¡ãããšããŠãŒã¶ãŒãdocker
ã°ã«ãŒãã«è¿œå ãããŸãã ããã確èªããã«ã¯ã $ id -nG
å®è¡ããŸãã ãªã¹ãã«ãããŠãŒã¶ãŒåã§åºåããã€ã¹ã«æ»ããšããã¹ãŠãæ£ããè¡ãããŠããŸãã
MacãšWindowsã¯ã©ãã§ããïŒ å¹žããªããšã«ãã€ã³ã¹ããŒã«ã¯ç°¡åã§ãã ã€ã³ã¹ããŒã«ãŠã£ã¶ãŒããèµ·åããç°¡åãªãã¡ã€ã«ãããŠã³ããŒãããŸãã ãã以äžç°¡åãªããšã¯ãããŸããã Macã®å Žåã¯ã€ã³ã¹ããŒã«ãŠã£ã¶ãŒãããWindowsã®å Žåã¯ãã¡ããã芧ãã ãã ã
ã³ã³ããå±é
Dockerããããã€ããŠå®è¡ããåŸãå°ãå®éšããããšãã§ããŸãã ä»äºãããå¿
èŠãããæåã®4ã€ã®ããŒã ïŒ
- create-ã³ã³ãããã€ã¡ãŒãžããäœæãããŸã;
- ps-å®è¡äžã®ã³ã³ããã®ãªã¹ãã衚瀺ãããŸãããªãã·ã§ã³ã§ããã¹ãŠã®ã³ã³ããã®ãªã¹ãã«
-a
ãã©ã°ã衚瀺ãããŸãã - start-äœæãããã³ã³ãããéå§ããŸãã
- attach-ã¿ãŒããã«ã®æšæºå
¥åãšåºåãäœæ¥ã³ã³ããã«æ¥ç¶ããä»®æ³ãã·ã³ã®ããã«æåéãã³ã³ããã«æ¥ç¶ããŸãã
å°ããå§ããŸãããã Docker HubããUbuntuã€ã¡ãŒãžãååŸããããããã³ã³ãããŒãäœæããŸãã
$ docker create -it ubuntu:16.04 bash
-it
ããªãã·ã§ã³ã®é¢æ°ãšããŠè¿œå ããŠãã³ã³ããã«çµ±å端æ«ãæäŸããŸãã ã¿ãŒããã«ã«æ¥ç¶ããŠã bash
ã³ãã³ããå®è¡ããããšãã§ããŸãã ubuntu: 16.04
æããŠãDocker Hubããã¿ã°ããŒãžã§ã³16.04ã®Ubuntuã€ã¡ãŒãžãååŸããŸãã
createã³ãã³ããå®è¡ããåŸãã³ã³ãããäœæãããããšã確èªããŸãã
$ docker ps -a
ãªã¹ãã¯æ¬¡ã®ããã«ãªããŸãã
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7643dba89904 ubuntu:16.04 "bash" X min ago Created name
ã³ã³ãããäœæãããå®è¡ããæºåãã§ããŸããã ã³ã³ãããŒã®start
ã¯ç°¡åã§ãã ã³ã³ãããŒã® start
IDã³ãã³ããæå®ããŸãã
$ docker start 7643dba89904
ã³ã³ãããŒãå®è¡ãããŠãããã©ãããå床確èªããŸããã -a
ãã©ã°ã¯ãããŸããã
$ docker ps
å®è¡äžã®å Žåã¯ãåå ããŠãã ããã
$ docker attach 7643dba89904
ã«ãŒãœã«ãå€åããŠããŸãã ãªãã§ïŒ ã³ã³ããã«å
¥ã£ãã°ããã ããã§ãã ããã§ãUbuntuã§æ
£ããŠããbashã³ãã³ãããã¯ã©ãŠãã§å®è¡ãããŠããã€ã³ã¹ã¿ã³ã¹ã®ããã«å®è¡ã§ããŸãã è©ŠããŠã¿ãŠãã ããã
$ ls
ãã¹ãŠãããŸãæ©èœãã $ ll
ã§ãæ©èœããŸãã å¿
èŠãªã®ã¯ãåçŽãªdockerã³ã³ãããŒã ãã§ãã ããã¯ãéçºããã¹ãããã®ä»äœã§ãã§ããå°ããªä»®æ³ãã©ãããã©ãŒã ã§ãïŒ ä»®æ³ãã·ã³ãéããœãããŠã§ã¢ã䜿çšããå¿
èŠã¯ãããŸããã ç§ã®ãã€ã³ãããã¹ãããã«ã¯ããã®å°ããªã³ã³ããã«äœããã€ã³ã¹ããŒã«ããŸãã ããŒãã®ã€ã³ã¹ããŒã«ã¯ããŸããããŸãã ã³ã³ãããçµäºããå Žåã¯ãexitãšå
¥åãexit
ã ã³ã³ãããåæ¢ãã $ docker ps -a
å
¥åããŠäžèŠ§è¡šç€ºã§ããŸãã
ã泚æ åDockerã³ã³ããã¯ããã©ã«ãã§sudo
ãšããŠæ©èœããŸããã€ãŸãã sudo
ã¯ååšããŸããã å®è¡ãããåã³ãã³ãã¯ã sudo
ç¹æš©ã§èªåçã«èµ·åãããŸãã
å®éã®ã·ããªãª
ãã®è³æã§äœæ¥ããæéã ããã¯ãå®éã®ãããžã§ã¯ããæ¬çªã¢ããªã±ãŒã·ã§ã³ã§äœ¿çšãããã®ã§ãã
ã¹ããŒãã¬ã¹ã³ã³ãããŸãã¯ãããã³ã«ïŒ
åè¿°ã®ããã«ãåã³ã³ããã¯åé¢ãããŠãããç¶æ
ã¯ä¿æãããŸããã ã€ãŸããã³ã³ãããåé€ãããšããã®å
容ã¯å®å
šã«åé€ãããŸãã
$ docker rm 7643dba89904
ãã®å Žåãã©ã®ããã«ããŒã¿ãä¿åããŸããïŒ
ããªã¥ãŒã ãèããããšããããŸããïŒ ããªã¥ãŒã ã䜿çšãããšããã¹ããã·ã³äžã®ãã£ã¬ã¯ããªãã³ã³ããå
ã®ãã£ã¬ã¯ããªã«ãããã§ããŸãã
$ docker create -it -v $(pwd):/var/www ubuntu:latest bash
æ°ããã³ã³ãããäœæããå Žåãäœæããããªã¥ãŒã ã瀺ã-v
ãã©ã°ãè¿œå ããŸãã ãã®ã³ãã³ãã¯ãã³ã³ãã¥ãŒã¿ãŒäžã®çŸåšã®äœæ¥ãã£ã¬ã¯ããªãã³ã³ããå
ã®/ var / www
ãã£ã¬ã¯ããªã«ãã€ã³ãããŸãã
$ docker start <container_id>
ã䜿çšããŠã³ã³ãããèµ·åããåŸãã¡ã€ã³ãã·ã³ã§ã³ãŒããç·šéããŠãã³ã³ããã®å€æŽã確èªã§ããŸãã ã€ã¡ãŒãžã®ä¿åããããŒã¿ããŒã¹ãã¡ã€ã«ã®ä¿åãŸã§ãããŸããŸãªãŠãŒã¹ã±ãŒã¹ã®ããŒã¿ãä¿åã§ããããã«ãªããŸããããã¡ãããã©ã€ããªããŒãæ©èœãå¿
èŠãªéçºçšã«ãä¿åã§ããŸãã
ã泚æ createã³ãã³ããšstartã³ãã³ãã¯ãrunã³ãã³ããšåæã«å®è¡ã§ããŸãã
$ docker run -it -d ubuntu:16.04 bash
ã泚æ å¯äžã®è¿œå ã¯-dãã©ã°ã§ãããã¯ã³ã³ãããããã¯ã°ã©ãŠã³ãã§åå¥ã«åäœããããã«æ瀺ããŸãã
ããªã¥ãŒã ã«ã€ããŠãããªã«è©±ããŠããã®ã¯ãªãã§ããïŒ
ããã€ãã®ç°¡åãªæé ã§ãéçãªWebãµã€ãããã¹ãããåçŽãªnginx WebãµãŒããŒãäœæã§ããŸãã
æ°ãããã£ã¬ã¯ããªãäœæãã奜ããªååãä»ããŸãã䟿å®äžã myappãšããååãä»ããŸãã å¿
èŠãªã®ã¯ã myappãã£ã¬ã¯ããªã«ç°¡åãªindex.htmlãã¡ã€ã«ãäœæããŠè²Œãä»ããã ãã§ãã
<html> <head> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc= sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous"> <title>Docker Quick Start</title> </head> <body> <div class="container"> <h1>Hello Docker</h1> <p>This means the nginx server is working.</p> </div> </body> </html>
= "ã¹ã¿ã€ã«ã·ãŒã"æŽåæ§=ãSHA256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc = SHA512-dTfge / zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz / ixG7ArTxmDjLXDmezHubeNikyKGVyQ == <html> <head> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc= sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous"> <title>Docker Quick Start</title> </head> <body> <div class="container"> <h1>Hello Docker</h1> <p>This means the nginx server is working.</p> </div> </body> </html>
ã¿ã€ãã«ããã¹ãä»ãã®å
±éWebããŒãžããããŸãã nginxã³ã³ãããèµ·åããããã«æ®ããŸãã
$ docker run --name webserver -v $(pwd):/usr/share/nginx/html -d -p 8080:80 nginx
Dockerããããnginxã€ã¡ãŒãžããã£ããã£ããŠãnginxãå³åº§ã«æ§æããŸãã ããªã¥ãŒã æ§æã¯äžèšã§è¡ã£ããã®ãšåæ§ã§ãã nginxãHTMLãã¡ã€ã«ããã¹ãããããã©ã«ãã®ãã£ã¬ã¯ããªãæããŠããŸãã æ°ããã®ã¯--name
ãã©ã¡ãŒã¿ãŒã§ãããã¯webserver
ããã³-p 8080: 80
ãŸãã ã³ã³ããããŒã80ããã¹ããã·ã³ã®ããŒã8080ã«ãããã³ã°ããŸãã ã myappãã£ã¬ã¯ããªã§ã³ãã³ããå¿ããã«å®è¡ããŠãã ããã
ã³ã³ãããŒã$ docker ps
ã§æ©èœãããã©ãŠã¶ãŒãŠã£ã³ããŠãèµ·åãããã©ããã確èªããŸãã http: // localhost: 8080
移åãhttp: // localhost: 8080
ã
ã»ãã®2ã3ã®ã³ãã³ãã§èµ·åããnginx WebãµãŒããŒããããŸãã å¿
èŠã«å¿ããŠindex.htmlã§ç·šéããŸãã ããŒãžããªããŒãããŠãã³ã³ãã³ããå€æŽãããããšã確èªããŸãã
ã泚æ stopã³ãã³ãã䜿çšããŠãå®è¡äžã®ã³ã³ãããåæ¢ã§ããŸãã
$ docker stop <container_id>
人çããã£ãšæ¥œã«ããæ¹æ³ã¯ïŒ
èšãåãããããŸãïŒäœãã2åè¡ãå¿
èŠãããå Žåã¯ãèªååããŸãã 幞ããªããšã«ãDockeããããåŠçããŸããã index.htmlãã¡ã€ã«ã䜿çšããŠã Dockerãã¡ã€ã«ãè¿œå ããŸãã 圌ã®ååã¯Dockerfile㧠ãæ¡åŒµåã¯ãããŸããã
# Dockerfile FROM nginx:alpine VOLUME /usr/share/nginx/html EXPOSE 80
Dockerfile -Dockerã€ã¡ãŒãžã®ã¢ã»ã³ããªæ§æã çŠç¹ã¯ç»åã«ãããŸã ïŒ nginxïŒalpineã€ã¡ãŒãžãã€ã¡ãŒãžã®ããŒã¹ãšããŠãã£ããã£ããããªã¥ãŒã ãäœæããããŒã80ãèšå®ããããšã瀺ããŸãã
ã€ã¡ãŒãžãäœæããããã«ãbuildã³ãã³ãããããŸãã
$ docker build . -t webserver:v1
.
Dockerãã¡ã€ã«ãã€ã¡ãŒãžã®ãã«ãã«äœ¿çšãããå Žæã瀺ãã -t
ã¯ã€ã¡ãŒãžã®ã¿ã°ãããŒã¯ããŸãã ã€ã¡ãŒãžã¯webserver:v1
ãšããŠç¥ãããŸãã
ãã®ã³ãã³ãã§ã¯ãDocker Hubããã€ã¡ãŒãžãæœåºããã®ã§ã¯ãªããç¬èªã®ã€ã¡ãŒãžãäœæããŸããã ãã¹ãŠã®ç»åã衚瀺ããã«ã¯ã images
ã³ãã³ãã䜿çšãimages
ã
$ docker images
äœæãããã€ã¡ãŒãžãå®è¡ããŸãã
$ docker run -v $(pwd):/usr/share/nginx/html -d -p 8080:80 webserver:v1
Dockerfile Strengthã¯ãã³ã³ããã«æäŸã§ããã¢ããªã³ã§ãã 奜ã¿ã«åãããŠã€ã¡ãŒãžãäºåã«äœæã§ããŸããç¹°ãè¿ãã®ã¿ã¹ã¯ãæ°ã«å
¥ããªãå Žåã¯ããã1ã¹ãããè¡ã£ãŠdocker-composeãã€ã³ã¹ããŒã«ããŠãã ãã ã
Docker-composeïŒ
Docker-composeã䜿çšãããšã1ã€ã®ã³ãã³ãããã³ã³ãããŒãäœæããŠå®è¡ã§ããŸãã ããããããã«éèŠãªããšã¯ãã³ã³ãããŒã®ã¯ã©ã¹ã¿ãŒå
šäœãæ§ç¯ããdocker-composeã䜿çšããŠæ§æã§ããããšã§ãã
ã€ã³ã¹ããŒã«ããŒãžã«ç§»åããŠãã³ã³ãã¥ãŒã¿ãŒã«docker-composeãã€ã³ã¹ããŒã«ããŸãã
Docker Composeãã€ã³ã¹ããŒã«ãã
ããã€ã¹ã«æ»ã£ããã $ docker-compose --version
å®è¡ããŸãã ããã€ãã®äœæ²ãæ±ããŸãã
Dockerfileãšãšãã«ãdocker -compose.ymlãšããå¥ã®ãã¡ã€ã«ãè¿œå ãããã®ã¹ããããã貌ãä»ããŸãã
# docker-compose.yml version: '2' services: webserver: build: . ports: - "8080:80" volumes: - .:/usr/share/nginx/html
ã€ã³ãã³ãã«ã¯æ³šæããŠãã ãããããããªããšã* docker-compose.yml **ãæ£ããæ©èœããŸããã å®è¡ããããã ãã«æ®ããŸãã
$ docker-compose up (-d)
ã泚æ docker-compose -d
ã³ãã³ãã®åŒæ°ã䜿çšããŠãåãé¢ãããç¶æ
ã§èµ·åããŸãã $ docker-compose ps
ãå®è¡ããŠçŸåšåäœããŠãããã®ã確èªãããã $ docker-compose stop
ã䜿çšããŠã³ã³ãããŒã$ docker-compose stop
ãŸãã
Dockerã¯ãçŸåšã®ãã£ã¬ã¯ããªïŒ .
ïŒã®Dockerfileããã€ã¡ãŒãžãåéããäžèšã®ããã«ããŒãã衚瀺ããããªã¥ãŒã ãããã¡ã³ãã«ãããŸãã äœãèµ·ãããèŠãŠãã ããïŒ ãã«ãããã³å®è¡ã³ãã³ãã§è¡ã£ãã®ãšåãããšã ä»ã§ã¯ããããã®ä»£ããã«docker-compose up
1ã€ã ãå®è¡ããŸãã
ãã©ãŠã¶ã«æ»ããšããã¹ãŠã以åãšåãããã«æ©èœããããšãããããŸãã å¯äžã®éãã¯ãã¿ãŒããã«ã§ã®éå±ãªã³ãã³ãã®èšè¿°ãäžèŠã«ãªã£ãããšã§ãã ããããDockerfile
ãšDockerfile
docker-compose.yml
2ã€ã®æ§æãã¡ã€ã«ã«çœ®ãæããŸããã ãããã®ãã¡ã€ã«ã¯äž¡æ¹ãšãGitãªããžããªã«è¿œå ã§ããŸãã ãªããããéèŠãªã®ã§ããïŒ äºæ³ã©ãããæ¬çªç°å¢ã§ã¯åžžã«æ£ããæ©èœããããã§ãã ãŸã£ããåãã³ã³ãããããã¯ãŒã¯ãéçšãµãŒããŒã«å±éãããŸãïŒ
ãã®ã»ã¯ã·ã§ã³ãçµäºããã«ã¯ãã³ã³ãœãŒã«ã«æ»ãããã¹ãŠã®ã³ã³ããã®ãªã¹ããå床衚瀺ããŸãã
$ docker ps -a
ã³ã³ãããåé€ããå Žåã¯ãåè¿°ã®rm
ã³ãã³ããå®è¡ã§ããŸãã ã€ã¡ãŒãžãåé€ããã«ã¯ã rmi
ã³ãã³ãã䜿çšããŸãã
$ docker rmi <image_id>
äžèŠã«ãªã£ãå Žåã¯ãã³ã³ããã®æ®äœç©ãæ®ããªãã§ãã ããã
ããåºãèŠéïŒ
Dockerãã³ã³ãããŒãäœæããããã®å¯äžã®ãã¯ãããžãŒã§ã¯ãªãããšã確èªããã®ã§ãããŸã人æ°ã®ãªããã¯ãããžãŒãééããªãèšåããªããã°ãªããŸããã Dockerã¯ãæãäžè¬çãªã³ã³ãããŒåãªãã·ã§ã³ã§ãã ãããã RKTãæ£åžžã«æ©èœããããã§ãã
æãäžããŠãã³ã³ããã®ãªãŒã±ã¹ãã¬ãŒã·ã§ã³ã«èšåããå¿
èŠããããŸãã æ°·å±±ã®äžè§ã«ã€ããŠã ã話ããŸããã Docker-composeã¯ãã³ã³ãããããã¯ãŒã¯ãäœæããããã®ããŒã«ã§ãã ãã ãã倧éã®ã³ã³ããã管çããæ倧ã®çšŒåæéãæäŸããå¿
èŠãçããå ŽåããªãŒã±ã¹ãã¬ãŒã·ã§ã³ã圹ç«ã¡ãŸãã
倧èŠæš¡ãªã³ã³ããããŒã¹ã®ã¯ã©ã¹ã¿ãŒã®ç®¡çã¯ç°¡åãªäœæ¥ã§ã¯ãããŸããã ã³ã³ããã®æ°ãå¢ããã«ã€ããŠãéåžžè¡ãããŸããŸãªDevOpsã¿ã¹ã¯ãèªååããæ¹æ³ãå¿
èŠã«ãªããŸãã ãªãŒã±ã¹ãã¬ãŒã·ã§ã³ã¯ããããããããã³ã³ããããããã¯ãŒã¯ã³ã³ãããªã©ãã¹ã±ãŒãªã³ã°ãŸãã¯åäœæããå¿
èŠãããå Žåã«ããã¹ãã®äœæãã³ã³ããã®äœæãŸãã¯åé€ã«åœ¹ç«ã€ãã®ã§ãã ãããŠããã§ã Googleã®Kubernetesãšç¬èªã®Dockeréçº-Swarm Modeãšãã次ã®ããŒã«ã圹ç«ã¡ãŸã ã
ãããã«
CaaSã䜿çšããããšã®å€§ããªå©ç¹ãšDockerã®ã·ã³ãã«ããçŽåŸã§ããªãã£ãå Žåãæ¢åã®ã¢ããªã±ãŒã·ã§ã³ã®1ã€ã確èªããŠDockerã³ã³ãããŒã«ç§»åããããšã匷ããå§ãããŸãã
Dockerã³ã³ããã¯ãéçºãã€ã³ã¹ããŒã«ããã¹ãããéçšã¢ããªã±ãŒã·ã§ã³ã®ãã¹ããŸã§ã奜ããªããšãå®è¡ã§ããå°ããªä»®æ³ãã·ã³ã§ãã
Dockerã®åäžæ§ã¯ãå®çšŒåç°å¢ã®éæ³ã®ãããªãã®ã§ãã ããã«ãããã¢ããªã±ãŒã·ã§ã³ã®å±éãšãµãŒããŒç®¡çã容æã«ãªããŸãã ãªããªããããŒã«ã«ã§æ©èœãããã®ã¯ã¯ã©ãŠãã§ãæ©èœããããã§ãã ããã¯ç§ãå·éãšåŒã¶ãã®ã§ãã 誰ããäœåºŠãèããããšãããæªåé«ãæã誰ãèããªãã§ãããã
ãŸããããã¯ç§ã®è»ã§åäœããŸã...
åºå
žïŒ Dockerã®ã¯ã©ãã·ã¥ã³ãŒã¹-倧ããªéãšæ³³ãããšãåŠã¶