尊龙凯时人生就是博

Docker×°ÖÃSymfony£ºÊµÏÖ¿ìËÙ¿ª·¢

Docker×°ÖÃSymfony£ºÊµÏÖ¿ìËÙ¿ª·¢

Ç°ÑÔ£º

SymfonyÊÇÒ»¸öÊ¢ÐеÄPHP¿ò¼Ü£¬ËüÌṩÁËÐí¶à¹¤¾ßºÍ×é¼þ£¬¿ÉÒÔ×ÊÖú¿ª·¢Õß¿ìËÙ¹¹½¨¸ßÖÊÁ¿µÄWebÓ¦ÓóÌÐò¡£¶øDockerÊÇÒ»ÖÖÈÝÆ÷»¯Æ½Ì¨£¬¿ÉÒÔʵÏÖÓ¦ÓõĿìËÙ°²ÅźÍÇéÐεĸôÀë¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«Ì½ÌÖÔõÑùʹÓÃDocker¾ÙÐÐSymfonyµÄ×°ÖúÍÉèÖã¬ÒÔʵÏÖ¿ìËÙ¿ª·¢¡£

×°ÖÃDockerºÍDocker Compose

ÔÚ×îÏÈ֮ǰ£¬ÄúÐèÒªÏÈÔÚÄúµÄ»úеÉÏ×°ÖÃDockerºÍDocker Compose¡£Äú¿ÉÒÔƾ֤ÄúµÄ²Ù×÷ϵͳÔÚDocker¹Ù·½ÍøÕ¾ÉÏÕÒµ½ÏìÓ¦µÄ×°Öý̳Ì¡£×°ÖÃÍê³Éºó£¬Äú¿ÉÒÔÔÚÖÕ¶ËÖÐÔËÐÐÒÔÏÂÏÂÁîÀ´ÑéÖ¤ÊÇ·ñ×°ÖÃÀֳɣº

docker --version
docker-compose --version

µÇ¼ºó¸´ÖÆ

½¨ÉèSymfonyÏîÄ¿

ÔÚÖÕ¶ËÖУ¬Ê¹ÓÃÒÔÏÂÏÂÁÉèÒ»¸öеÄSymfonyÏîÄ¿£º

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

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄÏÂÁʹÓÃComposer½¨ÉèÒ»¸öеÄSymfonyÏîÄ¿£¬ÏîÄ¿½«±»´æ´¢ÔÚÄ¿½ñĿ¼ÏµĔmy-symfony-app”Îļþ¼ÐÖС£

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

ÔÚSymfonyÏîÄ¿µÄ¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪ”docker-compose.yml”µÄÎļþ£¬ÓÃÓÚ½ç˵DockerÈÝÆ÷µÄÉèÖá£

version: "3"
services:
  web:
    build: .
    ports:
      - "8000:8000"
    volumes:
      - .:/app
    depends_on:
      - db
  db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: symfony
      MYSQL_USER: symfony
      MYSQL_PASSWORD: symfony

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄÉèÖÃÎļþ½ç˵ÁËÁ½¸öЧÀÍ£ºwebºÍdb¡£webЧÀÍʹÓÃÄ¿½ñĿ¼ÖеÄDockerfileÀ´¹¹½¨ÈÝÆ÷£¬²¢½«SymfonyÏîÄ¿¹ÒÔص½ÈÝÆ÷µÄ/appĿ¼ÖС£webЧÀÍ»¹½«ÈÝÆ÷µÄ8000¶Ë¿ÚÓ³Éäµ½Ö÷»úµÄ8000¶Ë¿Ú¡£dbЧÀÍʹÓùٷ½µÄMySQL¾µÏñ£¬²¢½ç˵ÁËһЩÇéÐαäÁ¿¡£

½¨ÉèDockerfile

ÔÚSymfonyÏîÄ¿µÄ¸ùĿ¼Ï½¨ÉèÒ»¸öÃûΪ”Dockerfile”µÄÎļþ£¬ÓÃÓÚ½ç˵½¨ÉèwebЧÀ͵ÄDocker¾µÏñµÄÉèÖá£

FROM node:14 AS build-node
WORKDIR /app
COPY . /app
RUN npm install && npm run build

FROM php:8.0-apache
WORKDIR /app
COPY --from=build-node /app /app
RUN docker-php-ext-install pdo pdo_mysql

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄDockerfileÎļþ½ç˵ÁËÁ½¸ö½×¶Î¡£ÔÚµÚÒ»¸ö½×¶Î£¬Ê¹ÓÃNode.js¾µÏñ¹¹½¨Ç°¶Ë×ÊÔ´¡£È»ºó£¬ÔÚµÚ¶þ¸ö½×¶Î£¬Ê¹ÓÃPHPºÍApache¾µÏñ¹¹½¨SymfonyÓ¦ÓóÌÐò£¬²¢½«Ç°¶Ë×ÊÔ´¸´ÖƵ½ÈÝÆ÷ÖС£

¹¹½¨ºÍÔËÐÐSymfonyÓ¦ÓóÌÐò

ÔÚÖÕ¶ËÖУ¬Ê¹ÓÃÒÔÏÂÏÂÁî¹¹½¨ºÍÔËÐÐSymfonyÓ¦ÓóÌÐò£º

docker-compose up -d --build

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄÏÂÁƾ֤docker-compose.ymlÎļþÖеÄÉèÖÃÀ´¹¹½¨ºÍÔËÐÐÈÝÆ÷¡£”-d”±ê¼Ç½«ÈÝÆ÷ÉèÖÃΪºǫ́ÔËÐС£

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

·­¿ªÄúµÄä¯ÀÀÆ÷£¬»á¼û”http://localhost:8000″£¬Äú½«Äܹ»¿´µ½SymfonyµÄ½Ó´ýÒ³Ãæ¡£ÖÁ´Ë£¬ÄúÒѾ­ÀֳɵØʹÓÃDocker×°ÖúÍÉèÖÃÁËSymfonyÓ¦ÓóÌÐò¡£

×ܽ᣺

±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃDockerºÍDocker ComposeÀ´×°ÖúÍÉèÖÃSymfonyÓ¦ÓóÌÐò¡£Í¨¹ý½«Symfony°²Åŵ½DockerÈÝÆ÷ÖУ¬ÎÒÃÇ¿ÉÒÔ¿ìËٴ¿ª·¢ÇéÐΣ¬²¢ÊµÏÖÓ¦ÓóÌÐòµÄ¿ìËÙ°²ÅźÍÇéÐεĸôÀ롣ϣÍû±¾ÎĶÔÄúÓÐËù×ÊÖú£¬×£ÄúÔÚSymfony¿ª·¢ÖÐÈ¡µÃÀֳɣ¡

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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