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
This commit is contained in:
27
Dockerfile
27
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 {} + && \
|
||||
|
||||
Reference in New Issue
Block a user