Dockerã®ã³ã³ããã¼ã§ã¢ããªã±ã¼ã·ã§ã³ãèµ·åããå ´åãå°ç¨ã®èµ·åã¹ã¯ãªããããã¢ããªã±ã¼ã·ã§ã³ãèµ·åãã¦ãæå¾ã«ï¼å¾ããdocker attachã§ããããã«ï¼bashãèµ·åãã¦ãããã¨ãããã¾ãã
次ã¯ãhttpdãµã¼ãã¹ãèµ·åããã³ã³ããã¼ãä½æããç°¡åãªDockerfileã§ãããã³ã³ããã¼èµ·åæã«ã¹ã¯ãªãããinit.shããå®è¡ããããã«ãã¦ãã¾ãã
Dockerfile
FROM centos:centos6 MAINTAINER enakai RUN yum -y install httpd ADD src /var/www/html RUN chmod -R 644 /var/www/html/* ADD init.sh /usr/local/bin/init.sh RUN chmod u+x /usr/local/bin/init.sh CMD ["/usr/local/bin/init.sh"]
ä¸æ¹ãã¹ã¯ãªããã®ä¸èº«ã¯ãããªæãã
init.sh
#!/bin/sh service httpd start /bin/bash
ããããªããããã®æ¹æ³ã®å ´åããdocker stopãã§ã³ã³ããã¼ãåæ¢ããéã«httpdãµã¼ãã¹ããããã«åæ¢ããä¸ã§ãã³ã³ããã¼ãåæ¢ããã¨ãããã¨ãã§ãã¾ããããdocker stopãã¯ããCMDãã§èµ·åããæåã®ããã»ã¹ï¼ãã®ä¾ã§ã¯ãinit.shãï¼ã«å¯¾ãã¦ãTERMã·ã°ãã«ãæããå¾ããã®ä»ã®ããã»ã¹ã¯å¼·å¶åæ¢ãã¦ãã¾ãã¾ãããdocker stopãã®éã«ããservice httpd stopããèªåå®è¡ãããã¨ã¯ã§ããªãã®ã§ããããï¼
ããã¯ã次ã®æ¹æ³ã§å®ç¾ã§ãã¾ããå ã»ã©ã®ãinit.shãã次ã®å 容ã«å ¥ãæ¿ãã¾ãã
init.sh
#!/bin/sh service httpd start cat <<EOF >>~/.bashrc trap 'service httpd stop; exit 0' TERM EOF exec /bin/bash
ããã¯ãexecã³ãã³ãã§bashãèµ·åãããã¨ã«ãããinit.shã®ããã»ã¹ãbashã«å ¥ãæ¿ãã¦ãã¾ããããã«ãããbashãTERMã·ã°ãã«ãåããããã«ãªãã¾ããããã«ã.bashrcã«trapã³ãã³ããä»è¾¼ããã¨ã§ãTERMã·ã°ãã«ã®ãã³ãã©ã¼ãè¨å®ãã¦ãã¾ããããã§ãTERMã·ã°ãã«ãåããbashã¯ããservice httpd stopãã§httpdãµã¼ãã¹ãåæ¢ããå¾ã«çµäºãã¦ããã¾ãã
ã°ã£ã¡ãã¼ã