DockerÔõÑù×°ÖÃSymfony¿ò¼Ü
DockerÔõÑù×°ÖÃSymfony¿ò¼Ü
СÐò£º
SymfonyÊÇÒ»¸öÊ¢ÐеÄPHP¿ò¼Ü£¬Í¨¹ýÌṩ¸»ºñµÄ¹¦Ð§ºÍ±ã½ÝµÄ¿ª·¢·½·¨£¬Ê¹µÃ¿ª·¢ÕßÄܹ»¿ìËÙ¹¹½¨¿ÉÀ©Õ¹µÄWebÓ¦ÓóÌÐò¡£ÔÚʹÓÃSymfony¿ò¼Ü¿ª·¢ÏîĿʱ£¬½èÖúDockerÈÝÆ÷»¯ÊÖÒÕ¿ÉÒÔÌṩһ¸öÇå½à¡¢Ò»ÖµĿª·¢ÇéÐΣ¬×ÊÖúÎÒÃǸü¸ßЧµØ¾ÙÐпª·¢ºÍ°²ÅÅ¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃDocker×°ÖúÍÉèÖÃSymfony¿ò¼Ü£¬²¢¸½ÓÐÏêϸµÄ´úÂëʾÀý¡£
°ì·¨1£º×°ÖÃDockerºÍDocker Compose
ÔÚ×îÏÈ֮ǰ£¬ÎÒÃÇÐèÒªÏÈ×°ÖÃDockerºÍDocker Compose¡£Docker¹Ù·½ÍøÕ¾ÌṩÁËÏêϸµÄ×°Öý̳̣¬¿ÉÒÔƾ֤×Ô¼ºµÄ²Ù×÷ϵͳѡÔñÏìÓ¦µÄ×°Ö÷½·¨¡£
°ì·¨2£º½¨ÉèSymfonyÏîÄ¿
ÔÚ×°ÖÃÍêDockerºÍDocker Composeºó£¬ÎÒÃÇ¿ÉÒÔ×îÏȽ¨ÉèSymfonyÏîÄ¿¡£Ê×ÏÈ£¬½¨ÉèÒ»¸öеÄĿ¼À´´æ·ÅSymfonyÏîÄ¿Ïà¹ØÎļþ£¬È»ºóÔÚÖÕ¶ËÖнøÈë¸ÃĿ¼£¬Ö´ÐÐÒÔÏÂÏÂÁ
docker run --rm --interactive --tty --volume $PWD:/app composer:latest create-project symfony/skeleton my_project_name
µÇ¼ºó¸´ÖÆ
ÉÏÊöÏÂÁîÖУ¬$PWD´ú±íÄ¿½ñĿ¼£¬my_project_nameÊÇÄãµÄÏîÄ¿Ãû³Æ¡£
Ö´ÐÐÀֳɺó£¬SymfonyÓ¦ÓóÌÐòµÄ»ù±¾½á¹¹½«»á±»½¨ÉèÔÚÄ¿½ñĿ¼ÏµÄmy_project_nameÎļþ¼ÐÖС£
°ì·¨3£ºÉèÖÃDocker ComposeÎļþ
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªÉèÖÃDocker ComposeÎļþÒÔ½¨ÉèÒ»¸ö°üÀ¨ApacheºÍPHPÈÝÆ÷µÄ¿ª·¢ÇéÐΡ£ÔÚSymfonyÏîÄ¿µÄ¸ùĿ¼ÖУ¬½¨ÉèÒ»¸öÃûΪdocker-compose.ymlµÄÎļþ£¬²¢ÔÚÆäÖÐÌí¼ÓÒÔÏÂÄÚÈÝ£º
version: '3' services: php: image: php:7.4-apache volumes: - './my_project_name:/var/www/html' ports: - '80:80' depends_on: - db db: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: my_project_name MYSQL_USER: my_project_name_user MYSQL_PASSWORD: my_project_name_password
µÇ¼ºó¸´ÖÆ
ÉÏÊöÉèÖÃÎļþÖУ¬ÎÒÃÇʹÓÃÁËPHP 7.4ºÍApache¾µÏñ×÷Ϊ×ðÁú¿Ê±¿ª·¢ÇéÐΣ¬Í¬Ê±ÉèÖÃÁËMySQL 5.7×÷Ϊ×ðÁú¿Ê±Êý¾Ý¿âЧÀÍ¡£Í¨¹ývolumesÖ¸Á½«SymfonyÏîĿĿ¼¹ÒÔص½ÈÝÆ÷µÄ/var/www/html·¾¶ÉÏ£¬ÕâÑùÎÒÃǾÍÄÜÔÚÈÝÆ÷ÄÚ²¿»á¼ûµ½ÏîÄ¿µÄ´úÂë¡£
°ì·¨4£ºÆô¶¯DockerÈÝÆ÷
ÔÚÉèÖúÃdocker-compose.ymlÎļþºó£¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÆô¶¯DockerÈÝÆ÷£º
docker-compose up -d
µÇ¼ºó¸´ÖÆ
¸ÃÏÂÁî»áÔÚºǫ́Æô¶¯ºÍÔËÐÐSymfonyÓ¦ÓóÌÐòËùÐèµÄËùÓÐÈÝÆ÷¡£
°ì·¨5£º¼ì²éSymfony¿ò¼Ü×°ÖÃ
ÔÚËùÓÐÈÝÆ÷Æô¶¯²¢Õý³£ÔËÐкó£¬ÎÒÃÇ¿ÉÒÔͨ¹ýä¯ÀÀÆ÷»á¼ûSymfonyµÄ½Ó´ýÒ³Ã棬ÒÔÈ·±£Symfony¿ò¼ÜÀÖ³É×°Öá£ÔÚä¯ÀÀÆ÷µØµãÀ¸ÊäÈëhttp://localhost£¬ÈôÊÇÄܹ»¿´µ½SymfonyµÄ½Ó´ýÒ³Ã棬ÄÇôÌåÏÖ×°ÖÃÀֳɡ£
ÈôÊÇ×°ÖÃÀú³ÌÖÐÓöµ½ÈκÎÎÊÌ⣬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÉó²éÈÝÆ÷µÄÈÕÖ¾ÐÅÏ¢£º
docker-compose logs
µÇ¼ºó¸´ÖÆ
×ܽ᣺
ͨ¹ýDockerÈÝÆ÷»¯ÊÖÒÕ×°ÖÃSymfony¿ò¼Ü¿ÉÒÔ¼ò»¯ÏîÄ¿µÄ°²ÅźÍά»¤£¬Í¬Ê±ÌṩÁËÒ»¸öͳһµÄ¿ª·¢ÇéÐΡ£Í¨¹ý±¾ÎÄÌṩµÄ°ì·¨ºÍ´úÂëʾÀý£¬Äú¿ÉÒÔ¿ìËٵشSymfonyµÄ¿ª·¢ÇéÐΣ¬²¢×îÏÈʹÓÃSymfony¿ò¼Ü¾ÙÐпª·¢ÊÂÇ顣ϣÍûÕâƪÎÄÕ¶ÔÄúÓÐËù×ÊÖú£¡
ÒÔÉϾÍÊÇDockerÔõÑù×°ÖÃSymfony¿ò¼ÜµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡