ʹÓÃDocker¿ìËÙ½¨ÉèSymfony¿ª·¢ÇéÐÎ
ʹÓÃDocker¿ìËÙ½¨ÉèSymfony¿ª·¢ÇéÐÎ
¸ÅÊö£º
SymfonyÊÇÒ»¿îÊ¢ÐеÄPHP¿ò¼Ü£¬¿ÉÒÔ×ÊÖú¿ª·¢Õß¿ìËÙ¹¹½¨¿ÉÀ©Õ¹µÄWebÓ¦ÓóÌÐò¡£ÎªÁËÔÚÍâµØ¿ª·¢ºÍ²âÊÔSymfonyÓ¦ÓóÌÐòʱÄܹ»ÌṩһÖÂÇÒ¿ÉÒÆÖ²µÄÇéÐΣ¬ÎÒÃÇ¿ÉÒÔʹÓÃDockerÀ´½¨ÉèSymfony¿ª·¢ÇéÐΡ£DockerÄܹ»Ìṩ¸ôÀëµÄÈÝÆ÷£¬¿ÉÒÔÔÚ²î±ðµÄÇéÐÎÖпìËÙ°²ÅÅÓ¦ÓóÌÐò¡£
±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃDockerÀ´¿ìËÙ½¨ÉèSymfony¿ª·¢ÇéÐΣ¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£
°ì·¨Ò»£º×°ÖÃDockerºÍDocker Compose
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚÍâµØÅÌËã»úÉÏ×°ÖÃDockerºÍDocker Compose¡£DockerÊÇÒ»¸ö¿ªÔ´µÄÈÝÆ÷»¯Æ½Ì¨£¬¿ÉÒÔ×ÊÖúÎÒÃǹ¹½¨¡¢°²ÅźÍÔËÐÐÈÝÆ÷»¯µÄÓ¦ÓóÌÐò¡£Docker ComposeÊÇÒ»¸ö¹¤¾ß£¬¿ÉÒÔʹÓÃYAMLÎļþÀ´½ç˵ºÍÖÎÀí¶à¸öDockerÈÝÆ÷µÄÓ¦ÓóÌÐò¡£
¿ÉÒÔͨ¹ýDocker¹Ù·½ÍøÕ¾£¨https://docs.docker.com/get-docker/£©ÉÏÌṩµÄ˵Ã÷£¬Æ¾Ö¤²Ù×÷ϵͳµÄ²î±ðÀ´×°ÖÃDockerºÍDocker Compose¡£
°ì·¨¶þ£º½¨ÉèDockerfile
ÔÚÏîÄ¿¸ùĿ¼Ï½¨ÉèÒ»¸öDockerfileÎļþ£¬ÓÃÓÚ½ç˵SymfonyÓ¦ÓóÌÐòµÄDocker¾µÏñ¡£
ÒÔÏÂÊÇÒ»¸öʾÀýµÄDockerfileÄÚÈÝ£º
# ʹÓûù´¡¾µÏñ FROM php:7.4-apache # ×°ÖÃËùÐèµÄÀ©Õ¹ RUN docker-php-ext-install pdo pdo_mysql # ¸´ÖÆÏîÄ¿Îļþµ½ÈÝÆ÷ÖÐ COPY . /var/www/html # ÉèÖÃApacheµÄÎĵµ¸ùĿ¼ ENV APACHE_DOCUMENT_ROOT /var/www/html/public RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf # ÉèÖÃApacheµÄURLÖØд RUN a2enmod rewrite # ×°ÖÃComposer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer # ×°ÖÃSymfonyÏÂÁîÐй¤¾ß RUN curl -sS https://get.symfony.com/cli/installer | bash
µÇ¼ºó¸´ÖÆ
ÒÔÉÏDockerfileʹÓÃÁ˹ٷ½ÌṩµÄPHP 7.4ºÍApache¾µÏñ×÷Ϊ»ù´¡¾µÏñ£¬²¢×°ÖÃÁËSymfonyËùÐèµÄÀ©Õ¹¡£½Ó×Å£¬½«SymfonyÏîÄ¿Îļþ¸´ÖƵ½ÈÝÆ÷ÖУ¬²¢ÉèÖÃApacheµÄÎĵµ¸ùĿ¼ºÍURLÖØд¡£×îºó£¬×°ÖÃComposerºÍSymfonyÏÂÁîÐй¤¾ß¡£
°ì·¨Èý£º½¨Éèdocker-compose.ymlÎļþ
ÔÚÏîÄ¿¸ùĿ¼Ï½¨ÉèÒ»¸ödocker-compose.ymlÎļþ£¬ÓÃÓÚ½ç˵ºÍÖÎÀíSymfonyÓ¦ÓóÌÐòµÄDockerÈÝÆ÷¡£
ÒÔÏÂÊÇÒ»¸öʾÀýµÄdocker-compose.ymlÄÚÈÝ£º
version: '3' services: app: build: context: . dockerfile: Dockerfile volumes: - .:/var/www/html ports: - 8000:80 restart: always
µÇ¼ºó¸´ÖÆ
ÒÔÉÏdocker-compose.ymlÎļþ½ç˵ÁËÒ»¸öÃûΪ”app”µÄЧÀÍ£¬Ê¹ÓÃ֮ǰ½¨ÉèµÄDockerfileÀ´¹¹½¨SymfonyÓ¦ÓóÌÐòµÄ¾µÏñ¡£Í¬Ê±£¬½«Ä¿½ñÏîĿĿ¼ӳÉäµ½ÈÝÆ÷ÖеÄ/var/www/htmlĿ¼£¬²¢½«ÈÝÆ÷µÄ80¶Ë¿ÚÓ³Éäµ½ÍâµØµÄ8000¶Ë¿Ú¡£
°ì·¨ËÄ£ºÊ¹ÓÃDocker Compose¹¹½¨ºÍÔËÐÐSymfonyÈÝÆ÷
ÔÚÏîÄ¿¸ùĿ¼Ï·¿ªÖն˻òÏÂÁîÐй¤¾ß£¬²¢ÔËÐÐÒÔÏÂÏÂÁîÀ´¹¹½¨ºÍÔËÐÐSymfonyÈÝÆ÷£º
docker-compose up -d
µÇ¼ºó¸´ÖÆ
ÉÏÊöÏÂÁʹÓÃdocker-compose.ymlÎļþÀ´¹¹½¨ºÍÔËÐÐSymfonyÈÝÆ÷£¬²¢½«ÆäÖÃÓÚºǫ́ÔËÐС£
ÏÖÔÚ£¬¿ÉÒÔͨ¹ý»á¼ûhttp://localhost:8000À´Éó²éSymfonyÓ¦ÓóÌÐòÔËÐеÄЧ¹û£¬ÈôÊÇÒ»ÇÐÕý³££¬Ä㽫¿´µ½SymfonyµÄ½Ó´ýÒ³Ãæ¡£
×ܽ᣺
ʹÓÃDocker¿ÉÒÔ¿ìËÙ½¨Éè¡¢°²ÅźÍÖÎÀíSymfony¿ª·¢ÇéÐΣ¬¿ÉÒÔ×ÊÖúÎÒÃÇÌá¸ß¿ª·¢Ð§ÂÊ£¬°ü¹ÜÓ¦ÓóÌÐòÔÚ²î±ðÇéÐÎÖеÄÒ»ÖÂÐԺͿÉÒÆÖ²ÐÔ¡£Í¨¹ýʹÓÃDockerfileºÍdocker-compose.ymlÎļþ£¬ÎÒÃÇ¿ÉÒÔ½ç˵ºÍÖÎÀíSymfonyÈÝÆ÷µÄÉèÖúÍÒÀÀµÏî¡£
Ï£Íû±¾ÎÄÌṩµÄʾÀý´úÂëºÍ°ì·¨ÄÜ×ÊÖúµ½Ä㣬¿ìËÙ½¨ÉèSymfony¿ª·¢ÇéÐβ¢¾ÙÐпª·¢ºÍ²âÊÔ¡£
ÒÔÉϾÍÊÇʹÓÃDocker¿ìËÙ½¨ÉèSymfony¿ª·¢ÇéÐεÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡