尊龙凯时人生就是博

ʹÓÃDocker×°ÖÃSymfony£ºÒ»²½²½Ö¸ÄÏ

ʹÓÃDocker×°ÖÃSymfony£ºÒ»²½²½Ö¸ÄÏ

SymfonyÊÇÒ»ÖÖÊ¢ÐеÄPHP¿ò¼Ü£¬ÉÁ¿ª·¢Ö°Ô±Äܹ»¿ìËÙ¹¹½¨¸ßÖÊÁ¿µÄWebÓ¦ÓóÌÐò¡£¶øDockerÊÇÒ»ÖÖÈÝÆ÷»¯Æ½Ì¨£¬¿ÉÒÔÇáËÉ°²ÅźÍÖÎÀíÓ¦ÓóÌÐò¡£ÍŽáʹÓÃSymfonyºÍDocker¿ÉÒÔ¼ò»¯ÇéÐÎÉèÖò¢Ìá¸ß¿ª·¢Ð§ÂÊ¡£±¾ÎĽ«Ö¸µ¼ÄãÒ»²½Ò»²½Í¨¹ýDocker×°ÖÃSymfony£¬ÒÔ¼°ÌṩÏêϸµÄ´úÂëʾÀý¡£

×°ÖÃDockerºÍDocker Compose

ҪʹÓÃDocker×°ÖÃSymfony£¬Ê×ÏÈÐèÒªÔÚÄãµÄÅÌËã»úÉÏ×°ÖÃDockerºÍDocker Compose¡£Äã¿ÉÒÔƾ֤ÄãµÄ²Ù×÷ϵͳÔÚ¹Ù·½ÍøÕ¾ÉÏÏÂÔز¢×°ÖÃËüÃÇ¡£×°ÖÃÍê³Éºó£¬Í¨¹ýÔËÐÐÒÔÏÂÏÂÁîÀ´Ñé֤װÖÃÊÇ·ñÀֳɣº

docker -v
docker-compose -v

µÇ¼ºó¸´ÖÆ

½¨ÉèSymfonyÏîÄ¿

ÔÚ×°ÖÃSymfony֮ǰ£¬ÄãÐèÒª½¨ÉèÒ»¸öеÄSymfonyÏîÄ¿¡£Çл»µ½ÏîÄ¿µÄÊÂÇéĿ¼£¬²¢Ê¹ÓÃÒÔÏÂÏÂÁÉèÒ»¸öÐÂÏîÄ¿£º

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

µÇ¼ºó¸´ÖÆ

Õ⽫ÔÚÄ¿½ñĿ¼Ï½¨ÉèÒ»¸öÃûΪ”myproject”µÄSymfonyÏîÄ¿¡£

ÉèÖÃDocker ComposeÎļþ

ÔÚÏîÄ¿µÄ¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪdocker-compose.ymlµÄÎļþ£¬²¢Ìí¼ÓÒÔÏÂÄÚÈÝ£º

version: '3'
services:
  php:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/app
    ports:
      - 8000:8000
    depends_on:
      - db
  db:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=myproject
      - MYSQL_USER=user
      - MYSQL_PASSWORD=pass

µÇ¼ºó¸´ÖÆ

Õâ¸öDocker ComposeÎļþÉèÖÃÁËÁ½¸öЧÀÍ£¬phpºÍdb¡£phpЧÀͽ«¹¹½¨Ò»¸ö»ùÓÚÄ¿½ñÏîĿĿ¼ÏµÄDockerfileµÄÈÝÆ÷£¬²¢½«ÏîĿĿ¼ӳÉäµ½ÈÝÆ÷µÄ/appĿ¼¡£Ëü»¹½«Ì»Â¶8000¶Ë¿ÚÒÔ±ãÓÚ»á¼ûSymfonyÓ¦ÓóÌÐò¡£dbЧÀͽ«Ê¹ÓÃMySQL 5.7¾µÏñ£¬²¢ÉèÖÃÁËһЩÇéÐαäÁ¿¡£

½¨ÉèDockerfile

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

FROM php:7.4-fpm

RUN apt-get update && apt-get install -y 
    git 
    unzip 
    libicu-dev 
    && docker-php-ext-install 
    intl 
    pdo_mysql 
    && pecl install apcu 
    && docker-php-ext-enable --ini-name 20-apcu.ini apcu

WORKDIR /app

COPY composer.json composer.lock ./

RUN composer install --prefer-dist --no-scripts --no-progress --no-suggest 
    && composer clear-cache

COPY . ./

CMD php -S 0.0.0.0:8000 -t public

µÇ¼ºó¸´ÖÆ

Õâ¸öDockerfile½«»ùÓÚphp:7.4-fpm¾µÏñ¹¹½¨Ò»¸öÈÝÆ÷¡£Ëü×°ÖÃÁËһЩ³£ÓÃÀ©Õ¹ºÍÒÀÀµÏ²¢½«SymfonyÓ¦ÓóÌÐòµÄĿ¼¸´ÖƵ½ÈÝÆ÷µÄ/appĿ¼¡£×îºó£¬ËüʹÓÃphpÏÂÁîÆô¶¯SymfonyÄÚÖÃWebЧÀÍÆ÷¡£

¹¹½¨ºÍÆô¶¯ÈÝÆ÷

ÔÚÏîÄ¿µÄ¸ùĿ¼Ï·­¿ªÖնˣ¬²¢Ö´ÐÐÒÔÏÂÏÂÁîÀ´¹¹½¨ºÍÆô¶¯ÈÝÆ÷£º

docker-compose up -d --build

µÇ¼ºó¸´ÖÆ

Õ⽫ʹÓÃDocker ComposeÎļþÖеÄÉèÖù¹½¨ºÍÆô¶¯phpºÍdbЧÀ͵ÄÈÝÆ÷¡£Äã¿ÉÒÔͨ¹ý»á¼ûhttp://localhost:8000À´ÑéÖ¤SymfonyÓ¦ÓóÌÐòÊÇ·ñÀÖ³ÉÔËÐС£

ÖÁ´Ë£¬ÄãÒѾ­ÀÖ³ÉʹÓÃDocker×°ÖÃÁËSymfony¡£ÏÖÔÚÄã¿ÉÒÔ×îÏÈ¿ª·¢ºÍ²âÊÔÄãµÄSymfonyÓ¦ÓóÌÐòÁË¡£Ã¿µ±ÄãÐèÒª×èÖ¹»òÆô¶¯SymfonyÓ¦ÓóÌÐò£¬Ö»ÐèÔËÐÐÒÔÏÂÏÂÁ

docker-compose stop   # ×èÖ¹ÈÝÆ÷
docker-compose start  # Æô¶¯ÈÝÆ÷

µÇ¼ºó¸´ÖÆ

×ܽ᣺

ʹÓÃDocker×°ÖÃSymfony¿ÉÒÔ¼ò»¯ÇéÐÎÉèÖ㬲¢ÌṩһÖÂÐԺͿÉÒÆÖ²ÐÔ¡£Í¨¹ýDocker ComposeµÄ×ÊÖú£¬ÎÒÃÇ¿ÉÒÔÇáËɵع¹½¨ºÍÖÎÀí¶à¸öÈÝÆ÷¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÌṩÁËÒ»¸öÏêϸµÄ°ì·¨ºÍ´úÂëʾÀý£¬×ÊÖúÄãʹÓÃDocker¿ìËÙ×°ÖúÍÔËÐÐSymfony¡£Ï£ÍûÕâƪÎÄÕÂÄܹ»×ÊÖúµ½Ä㣬ףÄãÔÚSymfony¿ª·¢ÖÐÈ¡µÃÀֳɣ¡

ÒÔÉϾÍÊÇʹÓÃDocker×°ÖÃSymfony£ºÒ»²½²½Ö¸ÄϵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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