½Ì³Ì£ºÊ¹ÓÃDockerÈÝÆ÷»¯×°ÖÃSymfony
½Ì³Ì£ºÊ¹ÓÃDockerÈÝÆ÷»¯×°ÖÃSymfony
СÐò£º
DockerÊÇÒ»ÖÖ¿ªÔ´µÄÈÝÆ÷»¯Æ½Ì¨£¬¿ÉÒÔ×ÊÖú¿ª·¢Õß¿ìËÙ¹¹½¨¡¢´ò°üºÍ°²ÅÅÓ¦ÓóÌÐò¡£SymfonyÊÇÒ»¸öÊ¢ÐеÄPHP¿ò¼Ü£¬ÌṩÁËÐí¶à¹¦Ð§Ç¿Ê¢µÄ¹¤¾ßºÍ×é¼þ£¬ÓÃÓÚ¿ª·¢¸ßÐÔÄܵÄWebÓ¦ÓóÌÐò¡£ÔÚ±¾½Ì³ÌÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùʹÓÃDockerÈÝÆ÷»¯×°ÖÃSymfony£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¹©²Î¿¼¡£
°ì·¨Ò»£º×°ÖÃDockerºÍDocker Compose
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚ×ðÁú¿Ê±¿ª·¢»úеÉÏ×°ÖÃDockerºÍDocker Compose¡£Çëƾ֤Docker¹Ù·½ÎĵµÖеÄ˵Ã÷¾ÙÐÐ×°Öá£
°ì·¨¶þ£º½¨ÉèSymfonyÏîÄ¿
ÔÚ×îÏÈ֮ǰ£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öSymfonyÏîÄ¿¡£·¿ªÖնˣ¬²¢Ö´ÐÐÒÔÏÂÏÂÁ
$ composer create-project symfony/skeleton symfony_project
µÇ¼ºó¸´ÖÆ
Õ⽫ÔÚÄ¿½ñĿ¼Ï½¨ÉèÒ»¸öÃûΪsymfony_projectµÄSymfonyÏîÄ¿¡£
°ì·¨Èý£º½¨ÉèDockerÎļþ
ÔÚÓëSymfonyÏîĿͬ¼¶µÄĿ¼Ï£¬½¨ÉèÒ»¸öÃûΪdocker-compose.ymlµÄÎļþ£¬²¢Ìí¼ÓÈçÏÂÄÚÈÝ£º
version: '3.8' services: web: image: php:7.4-apache volumes: - ./symfony_project:/var/www/html ports: - 8080:80 depends_on: - database database: image: mysql:5.7 environment: - MYSQL_DATABASE=your_database_name - MYSQL_USER=your_username - MYSQL_PASSWORD=your_password - MYSQL_ROOT_PASSWORD=your_root_password volumes: - ./mysql:/var/lib/mysql
µÇ¼ºó¸´ÖÆ
ÇëÈ·±£½«your_database_name£¬your_username£¬your_passwordºÍyour_root_passwordÌ滻ΪÄã×Ô¼ºµÄÊý¾Ý¿âÃû³Æ¡¢Óû§Ãû¡¢ÃÜÂëºÍÖÎÀíÔ±ÃÜÂë¡£
°ì·¨ËÄ£º¹¹½¨ºÍÔËÐÐDockerÈÝÆ÷
ÔÚÖÕ¶ËÖУ¬µ¼º½µ½°üÀ¨docker-compose.ymlÎļþµÄĿ¼£¬²¢Ö´ÐÐÒÔÏÂÏÂÁ
$ docker-compose up -d
µÇ¼ºó¸´ÖÆ
Õ⽫¹¹½¨ºÍÔËÐÐDockerÈÝÆ÷¡£-dÑ¡ÏÈÝÆ÷ÒÔºǫ́ģʽÔËÐС£
°ì·¨Î壺»á¼ûSymfonyÓ¦ÓóÌÐò
·¿ªä¯ÀÀÆ÷£¬²¢»á¼ûhttp://localhost:8080¡£ÄãÓ¦¸ÃÄܹ»¿´µ½SymfonyµÄ½Ó´ýÒ³Ãæ¡£ÏÖÔÚ£¬Äã¿ÉÒÔ×îÏÈÔÚSymfonyÏîÄ¿ÖоÙÐпª·¢ºÍ²âÊÔÁË¡£
°ì·¨Áù£ºÍ¨¹ýÏÂÁîÐлá¼ûSymfonyÈÝÆ÷
ÈôÊÇÄãÐèÒªÔÚSymfonyÈÝÆ÷ÄÚÖ´ÐÐÏÂÁ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
$ docker-compose exec web bash
µÇ¼ºó¸´ÖÆ
Õ⽫½øÈëSymfonyÈÝÆ÷µÄbash shell¡£ÔÚÕâ¸öshellÖУ¬Äã¿ÉÒÔÖ´ÐÐÈκÎÓëSymfonyÏîÄ¿Ïà¹ØµÄÏÂÁî¡£
¿¢ÊÂÓ
ͨ¹ýʹÓÃDockerÈÝÆ÷»¯×°ÖÃSymfony£¬ÎÒÃÇ¿ÉÒÔ¿ìËٴºÍÖÎÀíSymfonyÏîÄ¿µÄ¿ª·¢ÇéÐΣ¬ïÔÌÁËÇéÐÎÉèÖÃÎÊÌâ´øÀ´µÄƶÀ§£¬²¢Ìá¸ßÁË¿ª·¢Ð§ÂÊ¡£Ï£Íû±¾½Ì³ÌÄܶÔÄãÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊǽ̳̣ºÊ¹ÓÃDockerÈÝÆ÷»¯×°ÖÃSymfonyµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡