Dockerfile 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # 前端构建
  2. FROM node:alpine as frontend
  3. COPY package.json /app/
  4. RUN cd /app \
  5. && npm install --registry=https://registry.npm.taobao.org
  6. COPY webpack.mix.js /app/
  7. COPY resources/assets/ /app/resources/assets/
  8. RUN cd /app \
  9. && npm run production
  10. # 安装 Composer 依赖
  11. FROM composer as composer
  12. COPY database/ /app/database/
  13. COPY composer.json composer.lock /app/
  14. RUN cd /app \
  15. && composer config -g repo.packagist composer https://packagist.laravel-china.org \
  16. && composer install \
  17. --ignore-platform-reqs \
  18. --no-interaction \
  19. --no-plugins \
  20. --no-scripts \
  21. --prefer-dist
  22. # 整合 php环境
  23. FROM php:7.2-fpm-alpine as laravel
  24. ARG LARAVEL_PATH=/app/laravel
  25. COPY --from=composer /app/vendor/ ${LARAVEL_PATH}/vendor/
  26. COPY . ${LARAVEL_PATH}
  27. COPY --from=frontend /app/public/js/ ${LARAVEL_PATH}/public/js/
  28. COPY --from=frontend /app/public/css/ ${LARAVEL_PATH}/public/css/
  29. COPY --from=frontend /app/mix-manifest.json ${LARAVEL_PATH}/mix-manifest.json
  30. RUN cd ${LARAVEL_PATH} \
  31. && php artisan package:discover \
  32. && mkdir -p storage \
  33. && mkdir -p storage/framework/cache \
  34. && mkdir -p storage/framework/sessions \
  35. && mkdir -p storage/framework/testing \
  36. && mkdir -p storage/framework/views \
  37. && mkdir -p storage/logs \
  38. && chmod -R 777 storage
  39. # 启动 nginx
  40. FROM nginx:alpine as nginx
  41. ARG LARAVEL_PATH=/app/laravel
  42. COPY laravel.conf /etc/nginx/conf.d/
  43. COPY --from=laravel ${LARAVEL_PATH}/public ${LARAVEL_PATH}/public