ãDay004ãDockerã使ã£ãKaggleéçºç°å¢ã®æ§ç¯ï¼ãã®2ï¼::Ubuntuãå®è¡ãã
ããã«ã¡ã¯ããã¨ã·ã§ãã 9æã«ãªããä¸æ°ã«æ¶¼ãããªãã¾ãããã
ãã¨4ã¶æã§ä»å¹´ãçµãããã¨æãã¨è¸ç±ã§ãã
ãã¦ååãDockerã使ã£ã¦hello-worldã®ã¤ã¡ã¼ã¸ãå®è¡ãã¦ã¿ã¾ããã
ä»åã¯ãLinuxã®ãã£ã¹ããªãã¥ã¼ã·ã§ã³ã®Ubuntuãå®è¡ãã¾ãããã®ãªãã§ãã³ã³ããã®æ´æ°ããã³ã³ããã®å®è¡ãåèµ·åãªã©ãè¡ãã¾ãã
Ubuntuã®ã¤ã¡ã¼ã¸ãæã£ã¦ãã
ã¾ããDocker hubããUbuntuã¤ã¡ã¼ã¸ãæã£ã¦ãã¦èµ·åããã¾ããã³ãã³ãã¨ãã¦ã¯"docker run -it
$ docker run -it ubuntu bash
Ubuntuã®ã¤ã¡ã¼ã¸ã¯ã¾ã ãã¹ãã«ã¯ããã¾ãããããªãå ´åã«ã¯docker hubããpullãã¦ãã¦ããã¾ãã ãã®å¾ãã³ã³ãããä½ããã¦bashãåä½ããã³ãã³ãã«ãªãã¾ãã
ãã®æDocker hubãã4ã¤pullãã¦ããã®ãåããã¾ããããã¯ã¤ã¡ã¼ã¸ã¬ã¤ã¤ã«ãªã£ã¦ãã¾ãã
ãã®ã¤ã¡ã¼ã¸ã¬ã¤ã¤ã¯ããããç¬ç«ãã¦ãã¾ãããã®ãããæ°ããã¤ã¡ã¼ã¸ã¬ã¤ã¤ã追å ãããã¨ã§å ¨ä½ã¨ãã¦å¥ã®Dockerã¤ã¡ã¼ã¸ãä½ããã¨ãã§ãã¾ããã¤ã¾ãããã¨ãã¨ããé¨åãå ±éã§ä½¿ããã¨ã§ãªã½ã¼ã¹ã®ç¯ç´ãè¡ããæ°ãã«ã¤ã¡ã¼ã¸ã¬ã¤ã¤ã追å ãããã¨ã§æ°ããDockerã¤ã¡ã¼ã¸ãä½æãã³ã³ãããä½æãã¾ãã
å ¥ã£ãã³ã³ããããåºãå ´åã¯exitã®ã³ãã³ãã使ãã¾ãã
$ exit
Ubuntuã®ã³ã³ãããæ´æ°ãã
Docker imageãæ´æ°ããæ¹æ³ã¨ãã¦Docker fileãæ´æ°ããæ¹æ³ã¨ãã³ã³ããããæ´æ°ããæ¹æ³ãããã¾ããããã§ã¯ã³ã³ããããDocker imageãä½ãæ¹æ³ãè¡ãã¾ãã æ´æ°ããå 容ã§ããã"test"ã¨ãã空ãã¡ã¤ã«ãä½æãã¾ãã
ãã¡ã¤ã«ã追å ãã¦ãã®ã¬ã¤ã¤ãæ°ããã¬ã¤ã¤ã¨ãã¦è¿½å ããã¤ã¡ã¼ã¸ãä½æãã¾ãã
å ã»ã©ä½æããUbuntuã®ã¤ã¡ã¼ã¸ãç«ã¡ä¸ãã¾ãã
$ docker run -it ubuntu bash
Ubuntuãç«ã¡ä¸ãããbashãèµ·åãã¾ããèµ·åããã³ãã³ãã©ã¤ã³ãã"touch"ã³ãã³ããããã¡ã¤ã«ã追å ãã¾ãããã®å¾ãUbuntuãã"exit"ã«ããæãåºãã¾ãã
$ touch test $ exit
ããã«ãããã³ã³ããå ã«testãã¡ã¤ã«ã追å ããããã¨ã«ãªãã¾ãã
"docker ps -a"ã³ãã³ãã§ã³ã³ããã®ç¶æ ãã©ã®ããã«ãªã£ã¦ãããã確èªãã¾ãã
$ docker ps -a
ubuntuã¨ããã¤ã¡ã¼ã¸ããããbashã³ãã³ããæåã«å®è¡ããããã¨ããããã¾ãã
ã³ã³ãããåèµ·åãã
docker ps
ä¸åº¦ãåæ¢ããã³ã³ãããåèµ·åãã¾ããã¾ããã³ã³ããã®IDã¨ç¶æ ã確èªããããã"docker ps -a"ã³ãã³ããå®è¡ãã¾ãã
$ docker ps -a
ãã®æ ãã©ã¡ã¼ã¿ã®"CONTAINER ID"ã«ã³ã³ããã®IDãå ¥ãã¾ããããã¯èµ·åæã®ãã©ã¡ã¼ã¿ã¨ãã¦ä½¿ããã¨ãã§ãã¾ããã¾ããä»ã®ãã©ã¡ã¼ã¿ã«"STATUS"ãããã¾ããããã¯"Exited"ã«ãªã£ãããã¨ããããã¾ããã¤ã¾ããã³ã³ããã稼åãã¦ããªãã¨ã«ãªãã¾ãã
docker restart
ãã®ã³ã³ãããèµ·åããããã§ããä¸åº¦èµ·åãã¦æããããã³ã³ãããåèµ·åããã«ã¯"restart"ã³ãã³ãã使ç¨ãã¾ããåèµ·åããã³ã³ããã¯å ã»ã©ã®ã³ã³ããIDã使ãã¾ãã
$ docker restart ce1afc0e2d3a
å度"docker ps -a"ã³ãã³ããå®è¡ãã¦ã³ã³ããã®ç¶æ ã確èªãã¾ãã"Up"ã¨ãªã£ã¦ãããã¨ãããããã³ã³ããã稼åãã¦ãã¾ãã
docker exec
ã³ã³ããã稼åãã¦ãããã¨ããããã¾ããã®ã§ã次ã«ãã®ã³ã³ããã«å
¥ãã¾ããã³ã³ããã«å
¥ãããã«ã¯"docker exec -it
$ docker exec -it ce1afc0e2d3a bash
detachã¨attach
次ã«ã³ã³ããããæãã¾ããã³ã³ããããæããã«ã¯ä»ã¾ã§ã¯"exit"ã³ãã³ãã使ç¨ãã¦ãã¾ããããã®"exit"ã³ãã³ãã¯ã³ã³ãããæããéã«ããã»ã¹ãåã£ã¦æãã¾ãããã®ãã"docker ps"ã§ç¢ºèªã§ããã¹ãã¼ã¿ã¹ã"Exited"ã«ãªãã¾ãã
ãã®ããã»ã¹ãåããã«ã³ã³ããããæããæ¹æ³ã¨ãã¦detachãããã¾ããdetachãããã¨æããå¾ã®ã³ã³ããã®ã¹ãã¼ã¿ã¹ã"Up"ã®ã¾ã¾ã«ãªãã¾ãã
detatchã¯ã³ã³ããã«å ¥ã£ãå¾"Ctl + p +q"ã§å®è¡ããã¨ãã§ãã¾ãã
detachå¾ã®ç¨¼åä¸ã®ã³ã³ããã«åã³å ¥ãã¾ãã稼åä¸ã®ã³ã³ããã«å ¥ãã«ã¯"attach"ã³ãã³ãã使ãã¾ãã ã³ã³ããã«å ¥ãæ¹æ³ã¨ãã¦ã¯execã¨attachãããã¾ãã
"attach"ã¯ç¨¼åä¸ã®ã³ã³ããã® PIC=0 ã®ãã©ã¤ããªããã»ã¹ã«æ¥ç¶ãã¦ãexit ããã¨ã³ã³ãã³ãåæ¢ãã¾ãã
execã¯ç¨¼åä¸ã®ã³ã³ããã§å¥ããã»ã¹ãå®è¡ãã¾ãããã®å¾exit ããã¨ãã®ããã»ã¹ã®ã¿ãåæ¢ãã¾ãã
ã¾ã¨ã
ä»åã¯psãrestartãexecãdetachãattachãå®è¡ãã¦ã¿ã¾ãããããã»ã¹ã®åæ¢ãªã©ã¡ãã£ã¨ãããã«ããã§ãããã ãã ãæ £ããã®ã§ã¯ãªããã¨æãã¾ãã
Docker/Kubernetes å®è·µã³ã³ããéçºå ¥é
- ä½è :å±±ç° ææ²
- çºå£²æ¥: 2018/08/25
- ã¡ãã£ã¢: Kindleç