Dockerʵ¼ù£º×°ÖÃSymfony²¢´î½¨ÍêÕû¿ª·¢ÇéÐÎ
Dockerʵ¼ù£º×°ÖÃSymfony²¢´î½¨ÍêÕû¿ª·¢ÇéÐÎ
СÐò£º
DockerÊÇÒ»ÖÖÇáÁ¿¼¶¿ÉÒÆÖ²µÄÈÝÆ÷»¯Æ½Ì¨£¬ËüÔÊÐí¿ª·¢Ö°Ô±ÒÔÈÝÆ÷Ϊµ¥Î»¿ìËÙ¹¹½¨¡¢°²ÅźÍÔËÐÐÓ¦ÓóÌÐò¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùʹÓÃDockerÀ´×°ÖÃSymfony£¬²¢´î½¨Ò»¸öÍêÕûµÄ¿ª·¢ÇéÐΡ£ÎÒÃǽ«ÌṩÏêϸµÄ´úÂëʾÀý£¬ÒÔ×ÊÖúÄã¿ìËÙÉÏÊÖ¡£
Ò»¡¢×°ÖÃDockerºÍDocker Compose
ÔÚ×îÏÈ֮ǰ£¬ÎÒÃÇÊ×ÏÈÐèҪװÖÃDockerºÍDocker Compose¡£Äã¿ÉÒÔµ½Docker¹ÙÍøhttps://www.docker.com/ÏÂÔز¢×°ÖÃÊʺÏÄã²Ù×÷ϵͳµÄ°æ±¾¡£
¶þ¡¢½¨ÉèSymfonyÏîÄ¿
½ÓÏÂÀ´£¬ÎÒÃǽ«Ê¹ÓÃDockerÀ´½¨ÉèÒ»¸öSymfonyÏîÄ¿¡£Ê×ÏÈ£¬·¿ªÖն˻òÏÂÁîÌáÐÑ·û£¬½øÈëÄãÏ£Íû½¨ÉèÏîÄ¿µÄĿ¼ÖС£È»ºóÔËÐÐÒÔÏÂÏÂÁ
$ docker run --rm -v $(pwd):/app composer create-project symfony/website-skeleton myproject
µÇ¼ºó¸´ÖÆ
ÉÏÊöÏÂÁî»áÔÚÄ¿½ñĿ¼Ï½¨ÉèÒ»¸öÃûΪ”myproject”µÄSymfonyÏîÄ¿¡£ÄãÒ²¿ÉÒÔ½«”myproject”Ì滻ΪÄã×Ô¼ºµÄÏîÄ¿Ãû³Æ¡£
Èý¡¢ÉèÖÃDocker ComposeÎļþ
ÔÚÏîÄ¿µÄ¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪ”docker-compose.yml”µÄÎļþ£¬²¢Æ¾Ö¤ÒÔÏÂÄÚÈݾÙÐÐÉèÖãº
version: '3' services: web: build: context: . dockerfile: Dockerfile image: myproject ports: - "8000:8000" volumes: - .:/app depends_on: - db networks: - app_net db: image: mysql:5.7 environment: - MYSQL_DATABASE=symfony - MYSQL_USER=root - MYSQL_PASSWORD=root - MYSQL_ROOT_PASSWORD=root volumes: - db_data:/var/lib/mysql networks: - app_net networks: app_net: volumes: db_data:
µÇ¼ºó¸´ÖÆ
ÉÏÊöÉèÖÃÎļþ½ç˵ÁËÁ½¸öЧÀÍ£ºwebºÍdb¡£webЧÀÍÓÃÓÚÔËÐÐSymfonyÓ¦ÓóÌÐò£¬dbЧÀÍÓÃÓÚÔËÐÐMySQLÊý¾Ý¿â¡£ÎÒÃÇ»¹½ç˵ÁËÒ»¸ö¹²ÏíÍøÂçapp_net£¬²¢½«SymfonyÓ¦ÓóÌÐòºÍÊý¾Ý¿âÅþÁ¬µ½¸ÃÍøÂç¡£
ËÄ¡¢½¨ÉèDockerfileÎļþ
ÔÚÏîÄ¿µÄ¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪ”Dockerfile”µÄÎļþ£¬²¢Æ¾Ö¤ÒÔÏÂÄÚÈݾÙÐÐÉèÖãº
FROM php:7.4-apache WORKDIR /app RUN docker-php-ext-install pdo pdo_mysql RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
µÇ¼ºó¸´ÖÆ
ÉÏÊöDockerfile½ç˵ÁËÒ»¸ö»ùÓÚphp:7.4-apache¾µÏñµÄоµÏñ¡£ÎÒÃÇÔÚÆäÖÐ×°ÖÃÁËÐëÒªµÄPHPÀ©Õ¹ºÍComposer¡£
Îå¡¢¹¹½¨ºÍÔËÐÐÈÝÆ÷
ÎÒÃÇÒѾÍê³ÉÁËËùÓÐÐëÒªµÄÉèÖã¬ÏÖÔÚ¿ÉÒÔ×îÏȹ¹½¨ºÍÔËÐÐÈÝÆ÷ÁË¡£ÔÚÖն˻òÏÂÁîÌáÐÑ·ûÖУ¬½øÈëÏîÄ¿µÄ¸ùĿ¼£¬²¢ÔËÐÐÒÔÏÂÏÂÁ
$ docker-compose up -d
µÇ¼ºó¸´ÖÆ
ÉÏÊöÏÂÁî»áƾ֤ÉèÖÃÎļþ½¨Éè²¢ÔËÐÐÁ½¸öÈÝÆ÷£ºÒ»¸öÓÃÓÚÔËÐÐSymfonyÓ¦ÓóÌÐòµÄÈÝÆ÷£¬ÁíÒ»¸öÓÃÓÚÔËÐÐMySQLÊý¾Ý¿âµÄÈÝÆ÷¡£
Áù¡¢»á¼ûSymfonyÓ¦ÓóÌÐò
Ò»Çж¼×¼±¸Í£µ±ÁË£¬ÏÖÔÚ¿ÉÒÔͨ¹ýä¯ÀÀÆ÷»á¼ûSymfonyÓ¦ÓóÌÐòÁË¡£·¿ªä¯ÀÀÆ÷£¬²¢ÊäÈë”http://localhost:8000″¡£Ä㽫¿´µ½SymfonyµÄ½Ó´ýÒ³Ã棬֤ʵÄãµÄÓ¦ÓóÌÐòÒÑÀÖ³ÉÔËÐС£
Æß¡¢¸½¼ÓÉèÖúÍʹÓÃÆäËûЧÀÍ
³ýÁËÉÏÊöµÄ»ù±¾ÉèÖÃÖ®Í⣬Ä㻹¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇó¾ÙÐÐÌØÁíÍâÉèÖúÍʹÓÃÆäËûЧÀÍ¡£ÀýÈ磬Äã¿ÉÒÔÉèÖÃÓʼþ·¢ËÍSMTPЧÀÍÆ÷¡¢Ê¹ÓÃRedis»òÕßElasticsearchµÈ¡£
×ܽ᣺
±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃDockerÀ´×°ÖÃSymfony£¬²¢´î½¨Ò»¸öÍêÕûµÄ¿ª·¢ÇéÐΡ£ÎÒÃÇÌṩÁËÏêϸµÄ´úÂëʾÀý£¬×ÊÖúÄã¿ìËÙÉÏÊÖ¡£Ê¹ÓÃDocker¿ÉÒÔÌṩһÖÖÇáÁ¿¼¶¡¢¿ÉÒÆÖ²µÄ¿ª·¢ÇéÐΣ¬ÉÁ¿ª·¢Ö°Ô±Ô½·¢¸ßЧµØ¹¹½¨ºÍ°²ÅÅÓ¦ÓóÌÐò¡£Ï£Íû±¾ÎĶÔÄãÓÐËù×ÊÖú£¬×£ÄãÔÚSymfony¿ª·¢ÖÐÈ¡µÃÀֳɣ¡
ÒÔÉϾÍÊÇDockerʵ¼ù£º×°ÖÃSymfony²¢´î½¨ÍêÕû¿ª·¢ÇéÐεÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡