×ðÁú¿­Ê±¹ÙÍøµÇ¼

Docker×°ÖÃSymfony£º¼òÆÓ¿ì½ÝµÄ¿ª·¢ÇéÐÎ

Docker×°ÖÃSymfony£º¼òÆÓ¿ì½ÝµÄ¿ª·¢ÇéÐÎ

¸ÅÊö£º

SymfonyÊÇÒ»ÖÖÓÃÓÚ¹¹½¨ÏÖ´ú»¯WebÓ¦ÓóÌÐòµÄPHP¿ª·¢¿ò¼Ü¡£ÎªÁËÀû±ã¿ª·¢Ö°Ô±¿ìËٴSymfonyµÄ¿ª·¢ÇéÐΣ¬ÎÒÃÇ¿ÉÒÔʹÓÃDockerÈÝÆ÷À´¾ÙÐÐ×°ÖúÍÉèÖᣱ¾ÎĽ«ÏòÄúչʾÔõÑùʹÓÃDockerÀ´×°ÖÃSymfony£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£

°ì·¨Ò»£º×°ÖÃDocker

Ê×ÏÈ£¬ÄúÐèÒªÔÚÄúµÄ»úеÉÏ×°ÖÃDocker¡£DockerÊÇÒ»¸ö¿ªÔ´µÄÈÝÆ÷»¯Æ½Ì¨£¬¿ÉÒÔ×ÊÖúÎÒÃǹ¹½¨ºÍÖÎÀíÈÝÆ÷»¯µÄÓ¦ÓóÌÐò¡£Äú¿ÉÒÔ»á¼ûDocker¹Ù·½ÍøÕ¾£¨https://www.docker.com/£©ÏÂÔز¢×°ÖÃÊʺÏÄú²Ù×÷ϵͳµÄ°æ±¾¡£

°ì·¨¶þ£º½¨ÉèSymfonyÏîÄ¿

ÔÚ×°ÖÃÍêDockerÖ®ºó£¬ÎÒÃÇ¿ÉÒÔ×îÏȽ¨ÉèSymfonyÏîÄ¿¡£ÔÚÏÂÁîÐÐÖÐÖ´ÐÐÒÔÏÂÏÂÁ

$ docker run --rm -v $(pwd):/opt -w /opt composer create-project symfony/skeleton my_project

µÇ¼ºó¸´ÖÆ

ÉÏÊöÏÂÁʹÓÃComposerÔÚÄ¿½ñĿ¼Öн¨ÉèÒ»¸öÃûΪ”my_project”µÄSymfonyÏîÄ¿¡£

°ì·¨Èý£º½¨ÉèDockerfile

½ÓÏÂÀ´£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öÃûΪDockerfileµÄÎļþ£¬Ëü½«½ç˵SymfonyÏîÄ¿µÄDocker¾µÏñ¡£ÔÚÏîÄ¿¸ùĿ¼Öн¨ÉèÒ»¸öÃûΪDockerfileµÄÎļþ£¬²¢½«ÒÔÏÂÄÚÈݸ´ÖƵ½ÆäÖУº

# ʹÓÃPHP¹Ù·½¾µÏñ×÷Ϊ»ù´¡¾µÏñ
FROM php:7.4-apache

# ×°ÖÃSymfonyËùÐèµÄÀ©Õ¹
RUN apt-get update && apt-get install -y libicu-dev zip unzip git
RUN docker-php-ext-configure intl
RUN docker-php-ext-install intl
RUN docker-php-ext-install pdo pdo_mysql

# ¸´ÖÆSymfonyÏîÄ¿µ½ÈÝÆ÷ÖÐ
COPY . /var/www/html

# ÉèÖÃApacheµÄDocumentRoot
WORKDIR /var/www/html/public
RUN sed -ri -e 's!/var/www/html!/var/www/html/public!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!/var/www/html/public!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

# ÆôÓÃApacheµÄrewriteÄ£¿é
RUN a2enmod rewrite

µÇ¼ºó¸´ÖÆ

ÉÏÊöDockerfile½«¹¹½¨Ò»¸ö»ùÓÚPHP 7.4ºÍApacheµÄ¾µÏñ£¬²¢×°ÖÃSymfonyËùÐèµÄÀ©Õ¹¡£Ëü»¹½«¸´ÖÆSymfonyÏîÄ¿µ½ÈÝÆ÷ÖУ¬²¢ÉèÖÃApacheµÄDocumentRootΪÏîÄ¿µÄpublicĿ¼£¬ÒÔÈ·±£×¼È·µÄ·Óɺͻá¼û¡£

°ì·¨ËÄ£º¹¹½¨Docker¾µÏñ

ÔÚÏÂÁîÐÐÖнøÈëSymfonyÏîÄ¿µÄ¸ùĿ¼£¬²¢Ö´ÐÐÒÔÏÂÏÂÁîÀ´¹¹½¨Docker¾µÏñ£º

$ docker build -t my_symfony_app .

µÇ¼ºó¸´ÖÆ

ÉÏÊöÏÂÁʹÓÃDockerfileºÍÄ¿½ñĿ¼ÖеÄÄÚÈÝÀ´¹¹½¨Ò»¸öÃûΪ”my_symfony_app”µÄDocker¾µÏñ¡£

°ì·¨Î壺ÔËÐÐSymfonyÓ¦ÓÃ

ÔÚ¹¹½¨ÍêDocker¾µÏñÖ®ºó£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´ÔËÐÐSymfonyÓ¦Óãº

$ docker run -p 8080:80 my_symfony_app

µÇ¼ºó¸´ÖÆ

ÉÏÊöÏÂÁÆô¶¯Ò»¸öÈÝÆ÷£¬²¢½«ÈÝÆ÷µÄ80¶Ë¿ÚÓ³Éäµ½±¾»úµÄ8080¶Ë¿Ú¡£Òò´Ë£¬Äú¿ÉÒÔÔÚä¯ÀÀÆ÷Öлá¼û”http://localhost:8080″À´Éó²éÔËÐÐÖеÄSymfonyÓ¦Óá£

С½á£º

ʹÓÃDockerÀ´×°ÖÃSymfony¿ÉÒÔ×ÊÖúÎÒÃÇ¿ìËٴ¿ª·¢ÇéÐΣ¬²¢È·± £ÇéÐεÄÒ»ÖÂÐԺͿÉÒÆÖ²ÐÔ¡£±¾ÎÄͨ¹ý¸ø³öÏêϸµÄ´úÂëʾÀý£¬Ïò¸÷ÈËչʾÁËÔõÑùʹÓÃDockerÀ´×°ÖúÍÉèÖÃSymfony¡£Ï£ÍûÕâƪÎÄÕÂÄܹ»×ÊÖúÄúÇáËɵØ×îÏÈʹÓÃSymfony¾ÙÐÐWebÓ¦ÓóÌÐòµÄ¿ª·¢¡£

ÒÔÉϾÍÊÇDocker×°ÖÃSymfony£º¼òÆÓ¿ì½ÝµÄ¿ª·¢ÇéÐεÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ