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
|
WORKDIR /var/www
|
||||||
|
|
||||||
# Install system dependencies
|
# Install the PHP extension installer helper
|
||||||
RUN apk add --no-cache \
|
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
|
||||||
git \
|
|
||||||
curl \
|
|
||||||
libpng-dev \
|
|
||||||
oniguruma-dev \
|
|
||||||
libxml2-dev \
|
|
||||||
zip \
|
|
||||||
unzip \
|
|
||||||
libzip-dev \
|
|
||||||
icu-dev
|
|
||||||
|
|
||||||
# Install PHP extensions
|
# Install system dependencies and PHP extensions in one go
|
||||||
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip intl
|
# This script handles the 'apk add' and 'apk del' for dev-libraries automatically
|
||||||
|
RUN chmod +x /usr/local/bin/install-php-extensions && \
|
||||||
# Clear cache
|
install-php-extensions pdo_mysql mbstring exif pcntl bcmath gd zip intl
|
||||||
RUN rm -rf /var/cache/apk/*
|
|
||||||
|
|
||||||
# Get latest Composer
|
# Get latest Composer
|
||||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||||
|
|
||||||
# Copy application files and fix permissions
|
# Copy application files
|
||||||
COPY . /var/www
|
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 && \
|
RUN chown -R www-data:www-data /var/www && \
|
||||||
find /var/www -type d -exec chmod 755 {} + && \
|
find /var/www -type d -exec chmod 755 {} + && \
|
||||||
find /var/www -type f -exec chmod 644 {} + && \
|
find /var/www -type f -exec chmod 644 {} + && \
|
||||||
|
|||||||
Reference in New Issue
Block a user