尊龙凯时人生就是博

Docker×°ÖÃSymfony£º¿ìËٴ¿ª·¢ÇéÐÎÖ¸ÄÏ

Docker×°ÖÃSymfony£º¿ìËٴ¿ª·¢ÇéÐÎÖ¸ÄÏ

SymfonyÊÇÒ»ÖÖÊ¢ÐеÄPHP¿ò¼Ü£¬ËüÌṩÁËÒ»ÖÖ¿ìËÙ¡¢¿É¿¿ºÍ¿ÉÀ©Õ¹µÄ·½·¨À´¹¹½¨WebÓ¦ÓóÌÐò¡£Ëæ×ÅSymfonyµÄÆÕ¼°£¬Ðí¶à¿ª·¢Õ߶¼Ï£ÍûÄܹ»¿ìËٴSymfonyµÄ¿ª·¢ÇéÐΡ£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùʹÓÃDockerÀ´¿ìËÙ×°ÖÃSymfony£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£

Ìõ¼þÌõ¼þ£º

ÔÚ×îÏÈ֮ǰ£¬ÄúÐèҪװÖÃDockerºÍDocker Compose¡£Äú¿ÉÒÔ´Ó¹Ù·½ÍøÕ¾ÉÏÏÂÔغÍ×°ÖÃËüÃÇ£¬ÏêϸװÖÃÀú³ÌÇë²Î¿¼¹Ù·½Îĵµ¡£

½¨ÉèÒ»¸öSymfonyÏîÄ¿

Ê×ÏÈ£¬ÔÚÄúÏëÒª½¨ÉèSymfonyÏîÄ¿µÄĿ¼Ï·­¿ªÖն˻òÏÂÁîÐй¤¾ß¡£È»ºó£¬ÔËÐÐÒÔÏÂÏÂÁîÀ´½¨ÉèÒ»¸öеÄSymfonyÏîÄ¿£º

docker run --rm -v $(pwd):/app composer create-project symfony/website-skeleton myproject

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁʹÓÃComposerÀ´½¨ÉèÒ»¸öÃûΪ”myproject”µÄSymfonyÏîÄ¿¡£

½¨ÉèDockerÉèÖÃÎļþ

ÔÚSymfonyÏîÄ¿µÄ¸ùĿ¼Ï½¨ÉèÒ»¸öÐÂÎļþ£¬ÃüÃûΪdocker-compose.yml¡£È»ºó£¬½«ÒÔÏ´úÂ븴ÖƵ½Õâ¸öÎļþÖУº

version: '3.7'

services:
  webserver:
    image: nginx:alpine
    ports:
      - 80:80
    volumes:
      - ./myproject/public:/var/www/html
    depends_on:
      - php
  php:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ./myproject:/var/www/html

µÇ¼ºó¸´ÖÆ

Õâ¸öÉèÖÃÎļþ½ç˵ÁËÁ½¸öDockerЧÀÍ£ºwebserverºÍphp¡£webserverЧÀÍʹÓÃÁËNginx¾µÏñ£¬²¢½«Ö÷»úµÄ80¶Ë¿ÚÓ³Éäµ½ÈÝÆ÷µÄ80¶Ë¿Ú£¬½«SymfonyÏîÄ¿µÄ¹«¹²Îļþ¼Ð¹ÒÔص½ÈÝÆ÷µÄ/var/www/htmlĿ¼¡£phpЧÀͽ«Ê¹ÓÃÎÒÃÇÉԺ󽫽¨ÉèµÄDockerfile¡£

½¨ÉèDockerfile

ÔÚSymfonyÏîÄ¿µÄ¸ùĿ¼Ï½¨ÉèÒ»¸öÐÂÎļþ£¬ÃüÃûΪDockerfile¡£È»ºó£¬½«ÒÔÏ´úÂ븴ÖƵ½Õâ¸öÎļþÖУº

FROM php:7.4-fpm

RUN apt-get update && apt-get install -y 
    git 
    unzip 
    libpq-dev

RUN docker-php-ext-install pdo pdo_pgsql

WORKDIR /var/www/html

CMD ["php-fpm"]

EXPOSE 9000

µÇ¼ºó¸´ÖÆ

Õâ¸öDockerfile½ç˵ÁËÎÒÃǵÄphpЧÀÍËùÐèµÄ¾µÏñ£¬²¢×°ÖÃÁËһЩ³£ÓõÄÈí¼þ°üºÍÀ©Õ¹¡£

¹¹½¨DockerÈÝÆ÷

ÔÚSymfonyÏîÄ¿µÄ¸ùĿ¼Ï£¬ÔËÐÐÒÔÏÂÏÂÁîÀ´¹¹½¨ºÍÆô¶¯DockerÈÝÆ÷£º

docker-compose up -d

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁƾ֤docker-compose.ymlÎļþÖеÄÉèÖÃÀ´¹¹½¨ºÍÆô¶¯DockerÈÝÆ÷¡£ÇëÈ·±£ÄúÒѾ­ÔÚSymfonyÏîÄ¿µÄ¸ùĿ¼ÖÐÔËÐÐÕâ¸öÏÂÁî¡£

»á¼ûSymfonyÓ¦ÓóÌÐò

µ±DockerÈÝÆ÷ÀÖ³ÉÆô¶¯ºó£¬Äú¿ÉÒÔÔÚä¯ÀÀÆ÷Öлá¼ûhttp://localhost À´Éó²éSymfonyÓ¦ÓóÌÐò¡£ÄúÓ¦¸ÃÄܹ»¿´µ½SymfonyµÄ½Ó´ýÒ³Ãæ¡£

¸½¼ÓÐèÒªµÄ×é¼þ

ƾ֤ÄúµÄÏêϸÏîÄ¿ÐèÇó£¬Äú¿ÉÄÜÐèÒª¸½¼ÓһЩ×é¼þºÍ¿â¡£ºÃ±È£¬ÈôÊÇÄúÐèҪʹÓÃÊý¾Ý¿â£¬ÇëÔËÐÐÒÔÏÂÏÂÁîÀ´×°ÖÃDoctrine ORMºÍÊý¾Ý¿âÏà¹ØµÄÀ©Õ¹£º

docker exec -it myproject_php_1 composer require symfony/orm-pack
docker exec -it myproject_php_1 composer require symfony/maker-bundle --dev

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁÔÚÔËÐÐÖеÄphpÈÝÆ÷ÖÐ×°ÖÃÕâЩ×é¼þºÍÀ©Õ¹¡£

½øÒ»²½¶¨ÖÆ

Äú¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇó½øÒ»²½¶¨ÖÆSymfonyÏîÄ¿¡£¿ÉÒÔÐÞ¸Ädocker-compose.ymlÎļþÀ´Ìí¼Ó¸ü¶àµÄЧÀÍ£¬ºÃ±ÈÊý¾Ý¿âЧÀÍ¡£¿ÉÒÔÐÞ¸ÄDockerfileÀ´×°ÖÃÆäËûËùÐèµÄÀ©Õ¹¡£

×ܽ᣺

ͨ¹ýʹÓÃDocker£¬Äú¿ÉÒÔ¿ìËÙÀû±ãµØ´î½¨SymfonyµÄ¿ª·¢ÇéÐΡ£Í¨¹ýÉÏÊö°ì·¨£¬ÎÒÃǽ¨ÉèÁËÒ»¸ö°üÀ¨SymfonyÏîÄ¿ºÍÏà¹ØЧÀ͵ÄDockerÈÝÆ÷¡£Äú¿ÉÒÔƾ֤ÏîÄ¿ÐèÒª½øÒ»²½¶¨ÖÆÕâ¸öÇéÐΣ¬²¢ÇáËɵØÓëÍŶӳÉÔ±¹²Ïí¡£

Ï£ÍûÕâƪÎÄÕÂÄܹ»×ÊÖúÄú¿ìËٴSymfonyµÄ¿ª·¢ÇéÐΣ¬²¢¼ÓËÙÄúµÄ¿ª·¢Àú³Ì¡£×£ÄúÔÚʹÓÃSymfony¿ò¼Ü¿ª·¢WebÓ¦ÓóÌÐòʱȡµÃÀֳɣ¡

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

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

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

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

QR code
sitemap¡¢ÍøÕ¾µØͼ