Larvel + Vue 项目使用 Docker 作者: Chuwen 时间: 2021-12-28 分类: Docker 先给出配置文件,有空了再慢慢说道 ### Dockerfile: ```dockerfile FROM node:12-alpine as frontend WORKDIR /app ADD web-vue/package.json /app/ ADD web-vue/package-lock.json /app/ RUN npm install --registry=https://registry.npm.taobao.org ADD web-vue /app RUN npm run build # 第 1 个阶段,构建 composer 所需要的依赖包 FROM composer as composer COPY database/ /app/database/ COPY composer.json /app/ RUN set -x ; cd /app \ && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ \ && composer install \ --ignore-platform-reqs \ --no-interaction \ --no-plugins \ --no-scripts \ --prefer-dist # 第 2 个阶段 FROM shine09/php-fpm:73 as laravel ENV TZ="Asia/Shanghai" LANG="C.UTF-8" ARG LARAVEL_PATH=/app/laravel COPY --from=composer /app/vendor/ ${LARAVEL_PATH}/vendor/ COPY . ${LARAVEL_PATH} RUN set -x ; cd ${LARAVEL_PATH} \ && mv .env.docker .env \ && mkdir -p storage \ && mkdir -p storage/framework/cache \ && mkdir -p storage/framework/sessions \ && mkdir -p storage/framework/testing \ && mkdir -p storage/framework/views \ && mkdir -p storage/logs \ && chmod -R 777 storage \ && chmod -R 777 bootstrap/cache/ \ && php artisan package:discover # 第 3 个阶段 FROM nginx:alpine as nginx ENV TZ="Asia/Shanghai" LANG="C.UTF-8" ARG LARAVEL_PATH=/app/laravel COPY laravel.conf /etc/nginx/conf.d/ COPY --from=laravel ${LARAVEL_PATH}/public ${LARAVEL_PATH}/public COPY --from=frontend /app/net /app/frontend ``` ### docker-compose.yaml: ```yaml version: "3.7" services: php: build: context: . dockerfile: Dockerfile target: laravel container_name: project_app_server restart: always networks: - project_app nginx: build: context: . dockerfile: Dockerfile target: nginx container_name: project_app depends_on: - php ports: - "8092:80" networks: - project_app volumes: - ./logs/:/app/logs/ networks: project_app: driver: bridge name: project_app ``` ### laravel.conf: ```conf server { listen 80; server_name app.nowtime.cc; root /app/laravel/public; index index.php index.html; access_log /app/logs/$host.log; error_log /app/logs/$host.error.log; location / { try_files $uri $uri/ /index.php?$query_string; } location ^~ /app { alias /app/frontend; index index.html; try_files $uri $uri/ /app/index.html; } location ~ .*\.php(\/.*)*$ { fastcgi_pass project_app_server:9000; include fastcgi.conf; fastcgi_connect_timeout 10; fastcgi_send_timeout 10; fastcgi_read_timeout 10; } } ``` 标签: Laravel, Vue.js, docker-compose, Dockerfile