Docker×°ÖÃSymfonyµÄ½Ì³Ì£º¿ìËٴ¿ª·¢ÇéÐÎ
Docker×°ÖÃSymfonyµÄ½Ì³Ì£º¿ìËٴ¿ª·¢ÇéÐÎ
СÐò£º
SymfonyÊÇÒ»¸öÊ¢ÐеÄPHP¿ò¼Ü£¬ÓÃÓÚ¿ìËÙ¹¹½¨¿ÉÀ©Õ¹µÄWebÓ¦ÓóÌÐò¡£ÎªÁËÀû±ã¿ª·¢ÕßʹÓÃSymfony£¬ÎÒÃÇ¿ÉÒÔʹÓÃDockerÀ´¿ìËٴSymfonyµÄ¿ª·¢ÇéÐΡ£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃDocker×°ÖÃSymfony£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£
Ò»¡¢×°ÖÃDockerºÍDocker Compose
Ê×ÏÈ£¬ÎÒÃÇÐèҪװÖÃDockerºÍDocker Compose¡£DockerÊÇÒ»¸öÈÝÆ÷»¯Æ½Ì¨£¬¿ÉÒÔÇáËɵؽ¨Éè¡¢°²ÅźÍÖÎÀíÈÝÆ÷»¯µÄÓ¦ÓóÌÐò¡£Docker ComposeÔòÊÇÓÃÓÚ½ç˵ºÍÔËÐжà¸öDockerÈÝÆ÷µÄ¹¤¾ß¡£
ÔÚ×°ÖÃÁËDockerºÍDocker ComposeÖ®ºó£¬ÎÒÃǾͿÉÒÔ×îÏȴSymfonyµÄ¿ª·¢ÇéÐÎÁË¡£
¶þ¡¢½¨ÉèSymfonyÏîÄ¿
½¨ÉèÒ»¸öеÄÎļþ¼ÐÓÃÓÚ´æ·ÅSymfonyÏîÄ¿£º
mkdir symfony_project
µÇ¼ºó¸´ÖÆ
½øÈëÕâ¸öÎļþ¼Ð²¢Ê¹ÓÃComposer½¨ÉèÒ»¸öеÄSymfonyÏîÄ¿£º
cd symfony_project composer create-project symfony/website-skeleton .
µÇ¼ºó¸´ÖÆ
ÕâÑù¾Í½¨ÉèÁËÒ»¸öÃûΪ”symfony_project”µÄSymfonyÏîÄ¿¡£
Èý¡¢½¨ÉèDockerÈÝÆ÷
ÔÚSymfonyÏîÄ¿µÄ¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪ”docker”µÄÎļþ¼Ð£¬²¢½øÈë¸ÃÎļþ¼Ð£º
mkdir docker cd docker
µÇ¼ºó¸´ÖÆ
½¨ÉèÒ»¸öÃûΪ”docker-compose.yml”µÄÎļþ£¬²¢Ìí¼ÓÒÔÏÂÄÚÈÝ£º
version: '3' services: webserver: image: nginx:latest ports: - 80:80 volumes: - ../public:/var/www/html links: - php networks: - symfony php: image: php:7.4-fpm volumes: - ../:/var/www/html networks: - symfony networks: symfony:
µÇ¼ºó¸´ÖÆ
ÕâÀïÎÒÃÇʹÓÃÁËÁ½¸öÈÝÆ÷£¬Ò»¸öÓÃÓÚÔËÐÐSymfonyÓ¦ÓóÌÐòµÄNginxÈÝÆ÷£¬ÁíÒ»¸öÓÃÓÚÔËÐÐPHP-FPMµÄPHPÈÝÆ÷¡£ÕâÁ½¸öÈÝÆ÷¹²ÏíÁËͳһ¸öÍøÂ磨symfony£©£¬²¢ÇÒ½«SymfonyµÄ´úÂë¾í¹ÒÔص½Á˶ÔÓ¦µÄÈÝÆ÷ÖС£
ËÄ¡¢ÔËÐÐSymfonyÓ¦ÓóÌÐò
»Øµ½SymfonyÏîÄ¿µÄ¸ùĿ¼²¢ÔËÐÐÒÔÏÂÏÂÁÆô¶¯DockerÈÝÆ÷£º
cd .. docker-compose up -d
µÇ¼ºó¸´ÖÆ
ÕâÑù£¬Docker½«»á½¨Éè²¢Æô¶¯NginxºÍPHPÈÝÆ÷£¬È»ºóÎÒÃǾͿÉÒÔÔÚä¯ÀÀÆ÷Öлá¼ûSymfonyÓ¦ÓóÌÐòÁË¡£
ÔÚä¯ÀÀÆ÷ÖÐÊäÈë”http://localhost”£¬¼´¿ÉÉó²éSymfonyÓ¦ÓóÌÐòµÄ½Ó´ýÒ³Ãæ¡£
ÖÁ´Ë£¬ÎÒÃÇÒѾÀֳɵØʹÓÃDocker´î½¨ÁËSymfonyµÄ¿ª·¢ÇéÐΣ¬²¢ÇÒ¿ÉÒÔÔÚÍâµØ¾ÙÐпª·¢ºÍ²âÊÔÁË¡£
×ܽ᣺
±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃDocker×°ÖÃSymfony£¬²¢ÌṩÁËÏêϸµÄ´úÂëʾÀý¡£Í¨¹ýʹÓÃDocker£¬ÎÒÃÇ¿ÉÒÔÀû±ãµØ´î½¨SymfonyµÄ¿ª·¢ÇéÐΣ¬²¢ÇÒ¿ÉÒÔ¿ìËÙ°²Åŵ½ÆäËûÇéÐÎÖС£Ï£ÍûÕâ¸ö½Ì³Ì¹ØÓÚѧϰºÍʹÓÃSymfonyµÄ¿ª·¢ÕßÃÇÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇDocker×°ÖÃSymfonyµÄ½Ì³Ì£º¿ìËٴ¿ª·¢ÇéÐεÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡