# 本地部署用 Dockerfile # 基于 deploy/Dockerfile,额外安装 composer 依赖与前端构建产物 # 由 docker-compose.local.yml 使用 FROM php:8.3-apache-bookworm # ---------------- 系统依赖 + PHP 扩展 ---------------- ENV DEBIAN_FRONTEND=noninteractive # 切换到清华 Debian 镜像(国内访问 deb.debian.org 不稳) RUN sed -i 's|http://deb.debian.org|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list.d/debian.sources 2>/dev/null \ || sed -i 's|http://deb.debian.org|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list 2>/dev/null \ || true # 强制非交互式 dpkg 配置(避免 media-types 等包 conffile 提示卡住) RUN echo 'Dpkg::Options {"--force-confnew"; "--force-confdef";};' > /etc/apt/apt.conf.d/99force-conf \ && echo 'APT::Get::Assume-Yes "true";' >> /etc/apt/apt.conf.d/99force-conf RUN apt-get update \ && apt-get install -y --no-install-recommends \ ca-certificates \ curl \ libcurl4-openssl-dev \ libfreetype6-dev \ libicu-dev \ libjpeg62-turbo-dev \ libonig-dev \ libpng-dev \ libxml2-dev \ libzip-dev \ unzip \ zip \ git \ python3 \ make \ g++ \ && docker-php-ext-configure gd --with-freetype --with-jpeg \ && docker-php-ext-install -j"$(nproc)" \ bcmath \ curl \ dom \ exif \ gd \ intl \ mbstring \ pdo_mysql \ simplexml \ xml \ zip \ && a2enmod expires headers rewrite \ && rm -rf /var/lib/apt/lists/* # ---------------- Composer ---------------- COPY --from=composer:2 /usr/bin/composer /usr/bin/composer # ---------------- Node.js (LTS) ---------------- COPY --from=node:20-bookworm-slim /usr/local/bin/node /usr/local/bin/node COPY --from=node:20-bookworm-slim /usr/local/lib/node_modules /usr/local/lib/node_modules RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \ && ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx WORKDIR /var/www/html # ---------------- 复制源码 ---------------- COPY . /var/www/html COPY deploy/apache-vhost.conf /etc/apache2/sites-available/000-default.conf COPY deploy/php.ini /usr/local/etc/php/conf.d/jiangling.ini COPY deploy/entrypoint.sh /usr/local/bin/jiangling-entrypoint # ---------------- 安装 PHP 依赖(生产模式,跳过 ide-helper 等脚本)---------------- RUN composer install --prefer-dist \ --no-interaction \ --no-scripts \ --no-progress \ --no-ansi \ --no-dev \ && composer dump-autoload --no-scripts --no-dev --optimize # ---------------- 构建前端资源 ---------------- # 先装依赖(python3/make/g++ 让 node-sass 能编译) RUN npm install --no-audit --no-fund --legacy-peer-deps # 提升 node 堆内存上限;dev 模式无压缩,避免 mix/webpack 生产构建 OOM ENV NODE_OPTIONS="--max-old-space-size=2048" RUN npm run dev # ---------------- 目录与权限 ---------------- RUN chmod +x /usr/local/bin/jiangling-entrypoint \ && mkdir -p \ storage/app/public \ storage/app/temp \ storage/app/uploads \ storage/framework/cache/data \ storage/framework/sessions \ storage/framework/views \ storage/logs \ bootstrap/cache \ && chown -R www-data:www-data storage bootstrap/cache public ENTRYPOINT ["jiangling-entrypoint"] CMD ["apache2-foreground"]