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

Dockerʵ¼ù£º×°ÖÃSymfony²¢ÉèÖÃÇéÐÎ

Dockerʵ¼ù£º×°ÖÃSymfony²¢ÉèÖÃÇéÐÎ

СÐò£º

DockerÊÇÒ»¸ö¿ªÔ´µÄÈÝÆ÷»¯Æ½Ì¨ £¬Ëü¿ÉÒÔ×ÊÖúÎÒÃÇ¿ìËٴÇéÐΡ¢°²ÅÅÓ¦ÓúÍÖÎÀíÈÝÆ÷¡£ÔÚ±¾ÎÄÖÐ £¬ÎÒÃǽ«ÏÈÈÝÔõÑùʹÓÃDocker×°ÖÃSymfony £¬²¢ÉèÖÃÏìÓ¦µÄÇéÐΡ£

µÚÒ»²¿·Ö£º×°ÖÃDocker

ÔÚ×îÏÈ֮ǰ £¬ÇëÈ·±£ÒѾ­×°ÖÃÁËDocker¡£ÈôÊÇûÓÐ×°Öà £¬Çë²Î¿¼Docker¹Ù·½ÎĵµÍê³É×°Öá£

µÚ¶þ²¿·Ö£º½¨ÉèSymfonyÏîÄ¿

·­¿ªÖÕ¶Ë £¬²¢ÊäÈëÒÔÏÂÏÂÁîÀ´½¨ÉèSymfonyÏîÄ¿£º

$ docker run -it --rm -v $PWD:/app composer create-project symfony/skeleton my-symfony-project

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁî»áʹÓÃComposerÀ´½¨ÉèÒ»¸öSymfonyÏîÄ¿ £¬²¢½«Æä·ÅÔÚmy-symfony-projectÎļþ¼ÐÖС£

½øÈëÏîĿĿ¼£º

$ cd my-symfony-project

µÇ¼ºó¸´ÖÆ

µÚÈý²¿·Ö£º½¨ÉèDockerfile

ÔÚÏîÄ¿¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪDockerfileµÄÎļþ £¬²¢½«ÒÔÏÂÄÚÈÝÌí¼Óµ½ÎļþÖУº

FROM php:7.4-cli

# ×°ÖÃSymfonyËùÐèµÄÀ©Õ¹
RUN docker-php-ext-install pdo_mysql

# ×°ÖÃComposer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# ÉèÖÃÊÂÇéĿ¼
WORKDIR /app

# ¸´ÖÆÏîÄ¿Îļþµ½ÈÝÆ÷ÖÐ
COPY . .

# ×°ÖÃÏîÄ¿ÒÀÀµ
RUN composer install --no-dev --optimize-autoloader

# ̻¶ÈÝÆ÷µÄ80¶Ë¿Ú
EXPOSE 80

# Ö´ÐÐSymfonyµÄWebЧÀÍÆ÷ÏÂÁî
CMD php -S 0.0.0.0:80 -t public/

µÇ¼ºó¸´ÖÆ

Õâ¸öDockerfileÎļþ½ç˵Á˽¨ÉèSymfonyÈÝÆ÷µÄ°ì·¨¡£ËüʹÓÃÁËphp:7.4-cli¾µÏñ×÷Ϊ»ù´¡¾µÏñ £¬²¢×°ÖÃÁËSymfonyËùÐèµÄÀ©Õ¹ºÍComposer¡£È»ºó £¬½«ÏîÄ¿Îļþ¸´ÖƵ½ÈÝÆ÷ÖÐ £¬×°ÖÃÏîÄ¿ÒÀÀµ £¬²¢ÔÚÈÝÆ÷ÖÐ̻¶¶Ë¿Ú¡£

µÚËIJ¿·Ö£º¹¹½¨Docker¾µÏñ

ÔÚÖÕ¶ËÖÐÖ´ÐÐÒÔÏÂÏÂÁîÀ´¹¹½¨Docker¾µÏñ£º

$ docker build -t my-symfony-app .

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁî»áƾ֤Dockerfile¹¹½¨Ò»¸öÃûΪmy-symfony-appµÄ¾µÏñ¡£

µÚÎ岿·Ö£ºÔËÐÐSymfonyÓ¦ÓóÌÐò

ÔÚÖÕ¶ËÖÐÖ´ÐÐÒÔÏÂÏÂÁîÀ´Æô¶¯SymfonyÓ¦ÓóÌÐò£º

$ docker run -it --rm -p 8080:80 my-symfony-app

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁî»áÆô¶¯ÈÝÆ÷ £¬²¢½«ÈÝÆ÷µÄ80¶Ë¿ÚÓ³Éäµ½Ö÷»úµÄ8080¶Ë¿Ú¡£

µÚÁù²¿·Ö£ºÑéÖ¤SymfonyÓ¦ÓóÌÐò

ÔÚä¯ÀÀÆ÷Öлá¼ûhttp://localhost:8080 £¬¼´¿ÉÉó²éSymfonyÓ¦ÓóÌÐò¡£ÈôÊÇÒ»ÇÐÕý³£ £¬Äú½«¿´µ½SymfonyµÄ½Ó´ýÒ³Ãæ¡£

½áÂÛ£º

ͨ¹ýʹÓÃDocker £¬ÎÒÃÇ¿ÉÒÔ¿ìËٴSymfony¿ª·¢ÇéÐÎ £¬²¢Àû±ãµØ°²ÅÅÓ¦ÓóÌÐò¡£±¾ÎÄÏÈÈÝÁËÔõÑù×°ÖÃSymfony²¢ÉèÖÃÏìÓ¦µÄÇéÐÎ £¬Ï£Íû¶ÔÄúÓÐËù×ÊÖú¡£ÈôÊÇÄú»¹Ã»ÓÐʵÑé¹ýʹÓÃDockerÀ´ÖÎÀíÄúµÄÓ¦ÓóÌÐò £¬ÎÒÇ¿ÁÒ½¨ÒéÄú×îÏÈʵÑé £¬²¢ÏíÊÜÈÝÆ÷»¯´øÀ´µÄ±ãµ±¡£

ÒÔÉϾÍÊÇDockerʵ¼ù£º×°ÖÃSymfony²¢ÉèÖÃÇéÐεÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ