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

Symfony¿ò¼ÜµÄDocker×°ÖÃÖ¸ÄÏ

Symfony¿ò¼ÜµÄDocker×°ÖÃÖ¸ÄÏ

¸ÅÊö

DockerÊÇÒ»¸ö¿ªÔ´µÄÈÝÆ÷»¯Æ½Ì¨£¬¿ÉÓÃÓÚ¿ìËÙ¹¹½¨¡¢´ò°üºÍ°²ÅÅÓ¦ÓóÌÐò¡£Symfony¿ò¼ÜÊÇÒ»¸öÓÅÒìµÄPHP¿ò¼Ü£¬ÓÃÓÚ¿ìËÙ¿ª·¢ºÍά»¤¿Éά»¤µÄWebÓ¦ÓóÌÐò¡£ÍŽáDockerºÍSymfony¿ò¼Ü£¬¿ÉÒÔ¸ßЧµØ´î½¨ºÍÖÎÀíÓ¦ÓóÌÐòµÄ¿ª·¢ÇéÐΡ£

±¾ÎĽ«ÎªÄúÌṩһ·ÝÏêϸµÄSymfony¿ò¼ÜÔÚDockerÖеÄ×°ÖÃÖ¸ÄÏ£¬°üÀ¨ÏêϸµÄ´úÂëʾÀý¡£

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

Ê×ÏÈ£¬ÄúÐèÒªÔÚÍâµØ»úеÉÏ×°ÖÃDockerºÍDocker Compose¡£DockerµÄ×°Ö÷½·¨Òò²Ù×÷ϵͳ¶øÒ죬Ôڴ˲»ÔÙ׸Êö¡£¶øDocker ComposeÔòÊÇÒ»¸öÓÃÓÚ½ç˵ºÍÔËÐжàÈÝÆ÷DockerÓ¦ÓóÌÐòµÄ¹¤¾ß¡£Äú¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÀ´×°ÖÃDocker Compose£º

$ sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

µÇ¼ºó¸´ÖÆ

Íê³É×°Öúó£¬Äú¿ÉÒÔͨ¹ýdocker-compose –versionÏÂÁîÀ´ÑéÖ¤Docker ComposeµÄ×°ÖÃÊÇ·ñÀֳɡ£

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

½ÓÏÂÀ´£¬ÎÒÃǽ«Ê¹ÓÃSymfony CLIÀ´½¨ÉèÒ»¸öеÄSymfonyÏîÄ¿¡£ÇëÈ·±£ÄúÒѾ­ÔÚÍâµØ»úеÉÏ×°ÖÃÁËSymfony CLI¡£¿ÉʹÓÃÒÔÏÂÏÂÁîÀ´×°Öãº

$ curl -sS https://get.symfony.com/cli/installer | bash
$ mv ~/.symfony/bin/symfony /usr/local/bin/symfony

µÇ¼ºó¸´ÖÆ

×°ÖÃÀֳɺó£¬Äú¿ÉÒÔͨ¹ýsymfony –versionÏÂÁîÀ´ÑéÖ¤Symfony CLIµÄ×°ÖÃÊÇ·ñÀֳɡ£

ÏÖÔÚ£¬ÎÒÃÇ¿ÉÒÔʹÓÃSymfony CLIÀ´½¨ÉèÒ»¸öеÄSymfonyÏîÄ¿ÁË¡£ÔËÐÐÒÔÏÂÏÂÁ

$ symfony new my_project_name --full

µÇ¼ºó¸´ÖÆ

´ËÏÂÁ»áÔÚÄ¿½ñĿ¼Ï½¨ÉèÒ»¸öÃûΪmy_project_nameµÄSymfonyÏîÄ¿£¬²¢ÇÒʹÓÃÍêÕûµÄSymfonyÓ¦ÓóÌÐòÄ£°å¡£Õâ¸öÀú³Ì¿ÉÄÜÐèҪһЩʱ¼ä£¬ÇëÄÍÐÄÆÚ´ý¡£

°ì·¨Èý£º½¨ÉèDockerÉèÖÃÎļþ

ΪÁ˽«SymfonyÏîÄ¿ÔËÐÐÔÚDockerÈÝÆ÷ÖУ¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öDockerÉèÖÃÎļþ¡£ÔÚSymfonyÏîÄ¿µÄ¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪdocker-compose.yamlµÄÎļþ£¬²¢Ìí¼ÓÒÔÏÂÄÚÈÝ£º

version: '3'
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 8000:8000
    volumes:
      - .:/app
    depends_on:
      - db
  db:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=symfony
      - MYSQL_USER=symfony
      - MYSQL_PASSWORD=symfony
    volumes:
      - db_data:/var/lib/mysql
volumes:
  db_data:

µÇ¼ºó¸´ÖÆ

Õâ¸öÉèÖÃÎļþ½ç˵ÁËÁ½¸öЧÀÍ£¬»®·ÖÊÇwebºÍdb¡£webЧÀÍÓÃÓÚÔËÐÐSymfonyÓ¦ÓóÌÐòµÄWebЧÀÍ£¬²¢Ó³Éäµ½ÍâµØ»úеµÄ8000¶Ë¿Ú¡£dbЧÀÍʹÓÃMySQL 5.7¾µÏñ£¬²¢ÉèÖÃÁËһЩÇéÐαäÁ¿ºÍ¾í¡£

°ì·¨ËÄ£º½¨ÉèDockerfile

½ÓÏÂÀ´£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öÃûΪDockerfileµÄÎļþ£¬ÓÃÓÚ¹¹½¨SymfonyÏîÄ¿µÄDocker¾µÏñ¡£ÔÚSymfonyÏîÄ¿µÄ¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪDockerfileµÄÎļþ£¬²¢Ìí¼ÓÒÔÏÂÄÚÈÝ£º

FROM php:7.4-apache

RUN docker-php-ext-install pdo pdo_mysql
RUN a2enmod rewrite

WORKDIR /app
COPY . /app

RUN chown -R www-data:www-data /app

CMD ["apache2-foreground"]

µÇ¼ºó¸´ÖÆ

Õâ¸öDockerfileʹÓÃÁ˹ٷ½µÄPHP 7.4ÓëApache¾µÏñ£¬²¢×°ÖÃÁËPHPµÄpdoºÍpdo_mysqlÍØÕ¹¡£»¹ÆôÓÃÁËApacheµÄÖØд¹æÔò£¬²¢½«SymfonyÏîÄ¿µÄËùÓÐÎļþ¸´ÖƵ½ÈÝÆ÷µÄ/appĿ¼Ï¡£×îºó£¬Æô¶¯ApacheЧÀÍ¡£

°ì·¨Î壺¹¹½¨ºÍÔËÐÐDockerÈÝÆ÷

Íê³ÉÁËÉÏÊö°ì·¨ºó£¬ÎÒÃÇ¿ÉÒÔʹÓÃDocker ComposeÀ´¹¹½¨ºÍÔËÐÐSymfonyÏîÄ¿µÄDockerÈÝÆ÷¡£ÔÚSymfonyÏîÄ¿µÄ¸ùĿ¼ÏÂÔËÐÐÒÔÏÂÏÂÁ

$ docker-compose up -d

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁ»á×Ô¶¯¹¹½¨ºÍÔËÐÐÏîÄ¿µÄDockerÈÝÆ÷¡£-d²ÎÊýÓÃÓÚÔÚºǫ́ÔËÐÐÈÝÆ÷¡£

ÏÖÔÚ£¬Äú¿ÉÒÔͨ¹ýä¯ÀÀÆ÷»á¼ûhttp://localhost:8000À´Éó²éSymfonyÏîÄ¿µÄÔËÐÐÇéÐΡ£

½áÂÛ

ͨ¹ý±¾ÎĵÄÖ¸ÄÏ£¬Äú¿ÉÒÔÇáËɵؽ«Symfony¿ò¼ÜÓëDockerÏà͎ᣬ²¢¿ìËٴºÍÖÎÀíSymfonyÓ¦ÓóÌÐòµÄ¿ª·¢ÇéÐΡ£Ê¹ÓÃDockerµÄÈÝÆ÷»¯ÊÖÒÕ£¬¿ÉÒÔÌá¸ßÓ¦ÓóÌÐòµÄ¿ÉÒÆÖ²ÐÔºÍÀ©Õ¹ÐÔ£¬²¢¼ò»¯¿ª·¢Àú³ÌÖеÄÇéÐÎÉèÖá£Ï£Íû±¾Ö¸ÄÏÄܶÔÄúµÄSymfonyÏîÄ¿¿ª·¢ÊÂÇéÓÐËù×ÊÖú¡£

ÒÔÉϾÍÊÇSymfony¿ò¼ÜµÄDocker×°ÖÃÖ¸ÄϵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ