From 49226f8aa1f17ec6e9ae3b6beb4bb1a8245fbb15 Mon Sep 17 00:00:00 2001 From: Jp Date: Thu, 26 Feb 2026 13:27:58 +0800 Subject: [PATCH] build: simplify Dockerfile using extension installer - Replace manual apk install and docker-php-ext-install with mlocati/docker-php-extension-installer - Combine system dependency installation and PHP extension setup into a single step - Reorder steps for better clarity: copy files before permission fixes - Maintain same PHP extensions and final permissions --- Dockerfile | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 68cd306..2e09deb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,29 +2,22 @@ FROM php:8.4-fpm-alpine WORKDIR /var/www -# Install system dependencies -RUN apk add --no-cache \ - git \ - curl \ - libpng-dev \ - oniguruma-dev \ - libxml2-dev \ - zip \ - unzip \ - libzip-dev \ - icu-dev +# Install the PHP extension installer helper +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ -# Install PHP extensions -RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip intl - -# Clear cache -RUN rm -rf /var/cache/apk/* +# Install system dependencies and PHP extensions in one go +# This script handles the 'apk add' and 'apk del' for dev-libraries automatically +RUN chmod +x /usr/local/bin/install-php-extensions && \ + install-php-extensions pdo_mysql mbstring exif pcntl bcmath gd zip intl # Get latest Composer COPY --from=composer:latest /usr/bin/composer /usr/bin/composer -# Copy application files and fix permissions +# Copy application files COPY . /var/www + +# Fix permissions +# We do this as root before switching to the unprivileged user RUN chown -R www-data:www-data /var/www && \ find /var/www -type d -exec chmod 755 {} + && \ find /var/www -type f -exec chmod 644 {} + && \