ä¹ ãã¶ãã«æ°ããä¸ããä½ãWebã¢ããªã±ã¼ã·ã§ã³ãä½ãäºã«ãªããæ°å¹´ã¶ãã«è²ã æ å ±ãã¢ãããã¼ããã¾ããã
ãã¦ã
ã¢ããªã±ã¼ã·ã§ã³ã®éçºç°å¢ãä½ãå ´åããªãã¹ãåææ§ç¯æé ãç°¡ç¥åããããã®ã§ãã
ä»åã¯Docker ã§ç°å¢ãç«ã¡ä¸ããéã«ãLaravelã®åææ§ç¯ãè¡ãã³ãã³ããå®è¡ãã¦ãã¾ãæ¹æ³ã«ã¤ãã¦è§¦ãã¾ãã
Docker ã¤ã¡ã¼ã¸ã«ã¤ãã¦
ä¸è¬çãªWebã¢ããªã±ã¼ã·ã§ã³ã§ãç°¡åã«ä½ããæ§æã«ãã¾ããã
ã³ã³ãã | ãã¼ã¸ã§ã³ | å½¹å² |
---|---|---|
php | 8.0-apache | webãµã¼ãã¼ãå ¼ãã¢ããªã±ã¼ã·ã§ã³ãµã¼ãã¼ |
mysql | 8.0 | ãã¼ã¿ãã¼ã¹ãµã¼ãã¼ |
åææ§ç¯ããã³ãã³ã
åææ§ç¯ã®ã³ãã³ãã¯è²ã ããã¾ãããä»åã¯æ¬¡ã®ã³ãã³ããæ§ç¯æã«å®è¡ãããã¨æãã¾ãã
# å¿ è¦ãª php ã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã« $ composer install # ãã¼ããã·ã§ã³è¨å®(éçºç°å¢ãªã®ã§ç°¡åãªè¨å®ã§ã) $ chmod -R 777 /var/www/<Laravel ã®ããã¸ã§ã¯ããã£ã¬ã¯ããª> # Laravelã®ãã¤ã°ã¬ã¼ã·ã§ã³ $ php artisan migrate --seed # storage/public ãã£ã¬ã¯ããªã«ã·ã³ããªãã¯ãªã³ã¯ãè²¼ã $ php artisan storage:link
ã³ã³ããç«ã¡ä¸ãæã«ãã³ãã³ããå®è¡ããããã®æ¹æ³
ã³ã³ãããå®è¡ããéã«ãå
è¿°ããã³ãã³ããå®è¡ããå ´å㯠CMD
ã使ç¨ãã¾ãã
ã
docs.docker.jp
è¨å®ãã¦ããã¨ãdocker-compose up
ã§ç«ã¡ä¸ãã度ã«å®è¡ããã¾ãã
ä¸è¨ã³ãã³ããçºãã¦æ¬¡ã®ãããªæå®ããã¾ãã
// dockerfile
CMD bash -c "composer install && chmod -R 777 /var/www/<Laravelã®ããã¸ã§ã¯ããã£ã¬ã¯ããª> && php artisan migrate --seed && php artisan storage:link"
ãã®ç¶æ ã§ã³ã³ãããç«ã¡ä¸ããã¨ãã³ãã³ããä¸ï¼å·¦ï¼ããé ã«å®è¡ãã¦ããã¾ãã®ã§ä¸æ¬ã§ç°å¢ãä½ãäºãã§ãã¾ãã
php-apache ç³»ã®ã¤ã¡ã¼ã¸ã使ãå ´å
â»è¥å¹²ãä¸å®å ¨çç¼æãããå 容ã§ãã®ã§ãäºæ¿ãã ããã
php ã®Dockerã³ã³ããã¯ç¨éã«åããã¦è²ã æ±ã£ã¦ãã¾ãã
php-apache ç³»ã®ã¤ã¡ã¼ã¸ã¯webãµã¼ãã¼ã®å½¹å²ãæ ã£ã¦ãã¾ãã®ã§ãã³ã³ãããç«ã¡ä¸ããã¨apacheããã©ã¢ã°ã©ã¦ã³ãã§å®è¡ãã¾ãã
$ docker-compose up ... php-apache_1 | [Sat Jul 02 06:50:13.325205 2022] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.53 (Debian) PHP/8.0.20 configured -- resuming normal operations php-apache_1 | [Sat Jul 02 06:50:13.325253 2022] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
ã
ãããã
ä»åã®ããã«CMD
ã使ç¨ãã¦ãã¾ãã¨ãåæå®è¡ããã³ãã³ããä¸æ¸ããã¦ãã¾ããã¾ãã
ãã®ããã追å ãã CMD
ã®ã¹ã¯ãªãããå®è¡ããå¾ã«ã³ã³ãããæ¢ã¾ã£ã¦ãã¾ãã¾ãã
ã³ã³ãããæ¢ã¾ãã¨ãwebãµã¼ãã¼ãæ¢ã¾ãã¾ãã®ã§ãã©ã¦ã¶ã§è¡¨ç¤ºã§ããªããªãã¾ãã
ã³ã³ãããæ¢ããªãããã«ã¯ãCMD
ã®ã¹ã¯ãªããã®æå¾ã«çµäºå½ä»¤ãå
¥åãããã¾ã§å®è¡ãç¶ããã³ãã³ããå®è¡ãã¾ãã
ããç¨ããããæ¹æ³ã¨ãã¦ã \bin\bash
ãç¨ãã¦å¯¾è©±ç¶æ
ã«ããæ¹æ³ã§ãã
ä»åã¯webãµã¼ãã¼ãå ¼ä»»ãã¦ãã¾ãã®ã§ãapache ããã©ã¢ã°ã©ã¦ã³ãã§èµ·åãããäºã§ã³ã³ãããåããç¶ãã¾ãã
// dockerfile
CMD bash -c "composer install && chmod -R 777 /var/www/<Laravel ã®ããã¸ã§ã¯ããã£ã¬ã¯ããª> && php artisan migrate --seed && php artisan storage:link && apachectl -D FOREGROUND"
æ¸å¿µç¹
ä¸è¨ã®æ¹æ³ã§ç«ã¡ä¸ããå¾ããERROR: 2ãã¨è¨ãã¡ãã»ã¼ã¸ã表示ããã¾ãã
$ docker-compose up Killing php-apache ... done Killing mysql ... done ERROR: 2
å®è¡çµæãè¦ãã¨ã³ã³ãããéããã¦ãã¾ãã®ã§ãå·®ãå½ããåé¡ã¯ãªãããã§ãã
ã¨ã¯ãããè¥å¹²æ°æã¡æªãã§ããâ¦